Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class SavingsAccount
- {
- private:
- static double AnnualInterestRate;
- double SavingsBalance;
- static int ObjectCreated;
- static int ObjectDestroyed;
- public:
- SavingsAccount()
- {
- ObjectCreated++;
- cout<<"Object created "<<ObjectCreated<<endl;
- }
- ~SavingsAccount()
- {
- ObjectDestroyed++;
- cout<<"object destroyed "<<ObjectDestroyed<<endl;
- }
- void CalculateMonthlyInterest()
- {
- SavingsBalance=SavingsBalance+(SavingsBalance*AnnualInterestRate)/12;
- }
- static void ModifyInterestRate(double interest)
- {
- AnnualInterestRate=interest/100;
- }
- void SetSavings(double savings)
- {
- SavingsBalance=savings;
- }
- void display()
- {
- cout<<"The new balance is "<<SavingsBalance<<endl;
- }
- };
- double SavingsAccount::AnnualInterestRate=0.0;
- int SavingsAccount::ObjectCreated=0;
- int SavingsAccount::ObjectDestroyed=0;
- int main()
- {
- SavingsAccount saver1,saver2;
- saver1.SetSavings(2000.0);
- saver2.SetSavings(3000.0);
- SavingsAccount::ModifyInterestRate(3.00);
- saver1.CalculateMonthlyInterest();
- saver1.display();
- saver2.CalculateMonthlyInterest();
- saver2.display();
- SavingsAccount::ModifyInterestRate(4.00);
- saver1.CalculateMonthlyInterest();
- saver1.display();
- saver2.CalculateMonthlyInterest();
- saver2.display();
- }
Advertisement
Add Comment
Please, Sign In to add comment