Adrita

task1 (oop lab 4) 3rd sem

Jan 27th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class SavingsAccount
  4. {
  5. private:
  6. static double AnnualInterestRate;
  7. double SavingsBalance;
  8. static int ObjectCreated;
  9. static int ObjectDestroyed;
  10. public:
  11. SavingsAccount()
  12. {
  13. ObjectCreated++;
  14. cout<<"Object created "<<ObjectCreated<<endl;
  15. }
  16. ~SavingsAccount()
  17. {
  18. ObjectDestroyed++;
  19. cout<<"object destroyed "<<ObjectDestroyed<<endl;
  20. }
  21. void CalculateMonthlyInterest()
  22. {
  23. SavingsBalance=SavingsBalance+(SavingsBalance*AnnualInterestRate)/12;
  24. }
  25. static void ModifyInterestRate(double interest)
  26. {
  27. AnnualInterestRate=interest/100;
  28. }
  29. void SetSavings(double savings)
  30. {
  31. SavingsBalance=savings;
  32. }
  33. void display()
  34. {
  35. cout<<"The new balance is "<<SavingsBalance<<endl;
  36. }
  37.  
  38. };
  39. double SavingsAccount::AnnualInterestRate=0.0;
  40. int SavingsAccount::ObjectCreated=0;
  41. int SavingsAccount::ObjectDestroyed=0;
  42. int main()
  43. {
  44. SavingsAccount saver1,saver2;
  45. saver1.SetSavings(2000.0);
  46. saver2.SetSavings(3000.0);
  47.  
  48. SavingsAccount::ModifyInterestRate(3.00);
  49. saver1.CalculateMonthlyInterest();
  50. saver1.display();
  51. saver2.CalculateMonthlyInterest();
  52. saver2.display();
  53.  
  54. SavingsAccount::ModifyInterestRate(4.00);
  55. saver1.CalculateMonthlyInterest();
  56. saver1.display();
  57. saver2.CalculateMonthlyInterest();
  58. saver2.display();
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment