fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class Account
  4. {
  5. protected:
  6. int accno;
  7. string holdername;
  8. float balance;
  9. public:
  10. Account(int a, string n, int b)
  11. {
  12. accno=a;
  13. holdername=n;
  14. balance=b;
  15. }
  16. Account(const Account &a)
  17. {
  18. accno=a.accno;
  19. holdername=a.holdername;
  20. balance=a.balance;
  21. }
  22. ~Account() {}
  23. void deposit(float bucks)
  24. {
  25. balance+=bucks;
  26. }
  27. void withdraw(float bucks)
  28. {
  29. balance-=bucks;
  30. }
  31. void dispbalance()
  32. {
  33. cout<<"The balance is: "<<balance<<endl;
  34. }
  35. };
  36. class Savings: public Account
  37. {
  38. private:
  39. float intrate, minbalance;
  40. public:
  41. Savings(float r, int acc, string n, float blc): Account (acc, n, blc)
  42. {
  43. intrate=r;
  44. minbalance=500;
  45. }
  46. Savings(const Savings &ob) : Account (ob)
  47. {
  48. intrate=ob.intrate;
  49. minbalance=ob.minbalance;
  50. cout<<"Copy const called!\n";
  51. }
  52. bool checkminbalance()
  53. {
  54. if(balance<minbalance)
  55. {
  56. return true;
  57. }
  58. else return false;
  59. }
  60. float showbalance()
  61. {
  62. return balance;
  63. }
  64. float showintrate()
  65. {
  66. return intrate;
  67. }
  68. string Name()
  69. {
  70. return holdername;
  71. }
  72. void calculatemonthlyinterest()
  73. {
  74. if(!checkminbalance())
  75. {
  76. cout<<"The monthly interest this month is: "<<balance*intrate<<endl;
  77. balance+=(balance*intrate);
  78. }
  79. else
  80. {
  81. cout<<"Balance too low to add interest\n";
  82. return;
  83. }
  84. }
  85. };
  86. void comparemoney(Savings s1, Savings s2)
  87. {
  88. if(s1.showbalance()>s2.showbalance())
  89. {
  90. if(s1.showintrate()>s2.showintrate())
  91. {
  92. cout<<s1.Name()<<" has a greater balance and interest rate than "<<s2.Name()<<endl;
  93. }
  94. else cout<<s1.Name()<<" has a greater balance but a lesser interest rate than "<<s2.Name()<<endl;
  95. }
  96. else
  97. {
  98. if(s2.showintrate()>s1.showintrate())
  99. {
  100. cout<<s2.Name()<<" has a greater balance and interest rate than "<<s1.Name()<<endl;
  101. }
  102. else cout<<s2.Name()<<" has a greater balance but a lesser interest rate than "<<s1.Name()<<endl;
  103. }
  104. }
  105. int main()
  106. {
  107. cout<<"Person - 1:\n";
  108. int acc;
  109. cout<<"Account number: ";
  110. cin>>acc;
  111. string name;
  112. cout<<"Holder name: ";
  113. cin>>name;
  114. float balance;
  115. cout<<"Initial balance: ";
  116. cin>>balance;
  117. float intrate;
  118. cout<<"Interest rate(in fractions e.g 0.65, 0.35, etc): ";
  119. cin>>intrate;
  120. Savings s1(intrate, acc, name, balance);
  121. cout<<"The current balance is: "<<s1.showbalance()<<endl;
  122. cout<<"Amount to deposit: ";
  123. float bucks;
  124. cin>>bucks;
  125. s1.deposit(bucks);
  126. cout<<"The current balance is: "<<s1.showbalance()<<endl;
  127. cout<<"Amount to withdraw: ";
  128. cin>>bucks;
  129. s1.withdraw(bucks);
  130. cout<<"The current balance is: "<<s1.showbalance()<<endl;
  131. s1.calculatemonthlyinterest();
  132. cout<<"The current balance is: "<<s1.showbalance()<<endl;
  133.  
  134.  
  135. cout<<"Person - 2:\n";
  136. //int acc;
  137. cout<<"Account number: ";
  138. cin>>acc;
  139. //string name;
  140. cout<<"Holder name: ";
  141. cin>>name;
  142. //float balance;
  143. cout<<"Initial balance: ";
  144. cin>>balance;
  145. //float intrate;
  146. cout<<"Interest rate(in fractions e.g 0.65, 0.35, etc): ";
  147. cin>>intrate;
  148. Savings s2(intrate, acc, name, balance);
  149. cout<<"The current balance is: "<<s2.showbalance()<<endl;
  150. cout<<"Amount to deposit: ";
  151. //float bucks;
  152. cin>>bucks;
  153. s2.deposit(bucks);
  154. cout<<"The current balance is: "<<s2.showbalance()<<endl;
  155. cout<<"Amount to withdraw: ";
  156. cin>>bucks;
  157. s2.withdraw(bucks);
  158. cout<<"The current balance is: "<<s2.showbalance()<<endl;
  159. s2.calculatemonthlyinterest();
  160. cout<<"The current balance is: "<<s2.showbalance()<<endl;
  161. comparemoney(s1, s2);
  162. }
  163.  
  164.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Person - 1:
Account number: Holder name: Initial balance: Interest rate(in fractions e.g 0.65, 0.35, etc): The current balance is: 0
Amount to deposit: The current balance is: 7.46332e-42
Amount to withdraw: The current balance is: 0
Balance too low to add interest
The current balance is: 0
Person - 2:
Account number: Holder name: Initial balance: Interest rate(in fractions e.g 0.65, 0.35, etc): The current balance is: 0
Amount to deposit: The current balance is: 7.46332e-42
Amount to withdraw: The current balance is: 0
Balance too low to add interest
The current balance is: 0
Copy const called!
Copy const called!
 has a greater balance but a lesser interest rate than