Advertisement
Syndragonic

Display 10.1 CS311

Sep 10th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. //Program to demonstrate the CDAccount structure type.
  2. #include <iostream>
  3. //Q1 CDAccount has 3 members, 2 doubles and int
  4. //Q2 The parameter type of function for getData is struct CDAccount
  5. //Q3 The dot (.) operator is used as a separator or period from a refrence variable
  6. using namespace std;
  7. //Structure for a bank certificate of deposit:
  8. struct CDAccount
  9. {
  10. double balance;
  11. double interestRate;
  12. int term; //months until maturity
  13. };
  14.  
  15.  
  16. void getData(CDAccount& theAccount);
  17. //Postcondition: theAccount.balance and theAccount.interestRate
  18. //have been given values that the user entered at the keyboard.
  19.  
  20.  
  21. int main( )
  22. {
  23. CDAccount account;
  24. getData(account);
  25.  
  26. double rateFraction, interest;
  27. rateFraction = account.interestRate / 100.0;
  28. interest = account.balance * rateFraction * (account.term / 12.0);
  29. account.balance = account.balance + interest;
  30.  
  31. cout.setf(ios::fixed);
  32. cout.setf(ios::showpoint);
  33. cout.precision(2);
  34. cout << "When your CD matures in "
  35. << account.term << " months,\n"
  36. << "it will have a balance of $"
  37. << account.balance << endl;
  38. return 0;
  39. }
  40.  
  41. //Uses iostream:
  42. void getData(CDAccount& theAccount)
  43. {
  44. cout << "Enter account balance: $";
  45. cin >> theAccount.balance;
  46. cout << "Enter account interest rate: ";
  47. cin >> theAccount.interestRate;
  48. cout << "Enter the number of months until maturity\n"
  49. << "(must be 12 or fewer months): ";
  50. cin >> theAccount.term;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement