Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Savings Account class. Use a static data member annual Interest Rate to

ID: 3813248 • Letter: C

Question

Create a Savings Account class. Use a static data member annual Interest Rate to store the annual interest rate for each of the savers. Each member of the class contains a private data member savings Balance indicating the amount the saver currently has on deposit. Provide member function calculate Monthly Interest that calculates the monthly interest by multiplying the savings Balance by annual Interest Rate divided by 12; this interest should be added to savings Balance. Provide a static member function modify Interest Rate that sets the static annual Interest Rate to a new value. Write a driver program to test class Savings Account. Instantiate two different objects of class Savings Account, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set the annual Interest Rate to 3 percent. Then calculate the monthly interest and print the new balances for each of the savers. Then set the annual Interest Rate to 4 percent, calculate the next month's interest and print the new balances for each of the savers.

Explanation / Answer

#include<bits/stdc++.h>
#define ll long long

using namespace std;

class SavingsAccount
{
   double savingsBalance;
public:
   static double annualInterestRate;
   SavingsAccount(double opening_balance)
   {
       savingsBalance = opening_balance;
   }

   static void modifyInterestRate(double new_interest)
   {
       annualInterestRate = new_interest;
   }

   void calculateMonthlyInterest()
   {
       double temp = savingsBalance*annualInterestRate/(12);
       savingsBalance += temp;
   }

   void print_balance()
   {
       cout<<"Balance: "<<savingsBalance<<endl;
   }
};
double SavingsAccount::annualInterestRate = 0.03;

int main()
{
   SavingsAccount saver1(2000), saver2(3000);

   saver1.modifyInterestRate(0.03);
   saver1.calculateMonthlyInterest();
   saver2.calculateMonthlyInterest();
   saver1.print_balance();
   saver2.print_balance();

   saver1.modifyInterestRate(0.04);
   saver1.calculateMonthlyInterest();
   saver2.calculateMonthlyInterest();
   saver1.print_balance();
   saver2.print_balance();
   return 0;
}