(SavingsAccount Class) Create a SavingsAccount class. Use a static data member a
ID: 3542038 • Letter: #
Question
(SavingsAccount Class) Create a SavingsAccount class. Use a static data member annual-
InterestRate to store the annual interest rate for each of the savers. Each member of 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 balance 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 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. Then set the annualInterestRate to 4 percent,
calculate the next months 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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.