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

Create a SavingsAccount class. Use a static data member annualInterestRate to st

ID: 647176 • Letter: C

Question

Create a SavingsAccount class. Use a static data member annualInterestRate to store the annual interest rate for each of the savers. (Hint: define or initialize static variable outside class)

The class contains a private data member savingsBalance indicating the amount the saver currently has on deposit.

Provide member function calculateMonthlyInterest that calculates the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12; this interest should be added to savingsBalance.

Provide a static member function modifyInterestRate that sets the static annualInterestRate to a new value.

Write a driver program (containing main) to test class SavingsAccount.

Instantiate two different objects of class SavingsAccount, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively.

Set the annualInterestRate to 3 percent.

Then calculate the monthly interest and print the new balances for each of the savers.

Explanation / Answer

#include<iostream>
#include<iomanip>
using namespace std;
class SavingsAccount
{
private:
static double annual_Interest_Rate;
double savingsBalance;
public:
SavingsAccount(int sb=0)
{
savingsBalance = sb;
}
void calculateMonthlyInterest()
{
savingsBalance = savingsBalance + (savingsBalance*annual_Interest_Rate/12);
}
static void modifyInterestRate(double air)
{
annual_Interest_Rate = air;
}
double get_balance()
{
return savingsBalance;
}
};

double SavingsAccount::annual_Interest_Rate = 0.03;
int main()
{
SavingsAccount saver1(2000);
SavingsAccount saver2(3000);
SavingsAccount::modifyInterestRate(0.03);
cout << "Saver 1 Balance Saver 2 Balance " << endl;
cout << setw(10) << saver1.get_balance() << " " << setw(10) << saver2.get_balance() << endl;
for(int i=1; i<12; i++)
{
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
cout << setw(10) << saver1.get_balance() << " " << setw(10) << saver2.get_balance() << endl;
}
SavingsAccount::modifyInterestRate(0.04);
return 0;
}