Advertisement
Syndragonic

Lab 4 Code 1 CS311

Sep 22nd, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. #include<iomanip>
  4.  
  5. using namespace std;
  6.  
  7. /*class CDAccount replaces the structure*/
  8.  
  9. class CDAccount{
  10.  
  11. //private variables
  12.  
  13. double balance;
  14.  
  15. double interest_rate;
  16.  
  17. int term; //months until maturity
  18.  
  19. //public getters for variables and constructors
  20.  
  21. public:
  22.  
  23. CDAccount()
  24.  
  25. {
  26.  
  27. balance=0.0;
  28.  
  29. interest_rate=0.0;
  30.  
  31. term=0;
  32.  
  33. }
  34.  
  35. CDAccount(double b,double i,int t)
  36.  
  37. {
  38.  
  39. balance=b;
  40.  
  41. interest_rate=i;
  42.  
  43. term=t;
  44.  
  45. }
  46.  
  47. double getBalance()
  48.  
  49. {
  50.  
  51. return balance;
  52.  
  53. }
  54.  
  55. double getInterestRate()
  56.  
  57. {
  58.  
  59. return interest_rate;
  60.  
  61. }
  62.  
  63. double getTerm()
  64.  
  65. {
  66.  
  67. return term;
  68.  
  69. }
  70.  
  71. //get input method that accepts only istream as param
  72.  
  73. void getInput(istream& cin)
  74.  
  75. {
  76.  
  77. cin>>balance;
  78.  
  79. cin>>interest_rate;
  80.  
  81. cin>>term;
  82.  
  83. }
  84.  
  85. //get the calculated maturity value
  86.  
  87. double getMaturityValue()
  88. {
  89. return balance+(balance*(interest_rate/100.0)*term/12);
  90. }
  91. //output method for displaying the result
  92. //it accept ostream as param
  93. void output(ostream& cout)
  94. {
  95. cout<<"\n\nBalacnce : $"<<balance<< "\nInterest Rate : "<<interest_rate<<"\nTerm : "<<term<<"\nMaturity Value : $"<<getMaturityValue()<<endl;
  96. }
  97. };
  98. int main(void)
  99. {
  100. //created object of CDAccount
  101. CDAccount ac;
  102. cout<<"Please enter the Balance , Interest Rate and Term, Hit the enter/return after entering each value\n\n";
  103. //getting the input
  104. ac.getInput(std::cin);
  105. //printing the output
  106. ac.output(std::cout);
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement