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

SavingsAccount class program Create a SavingsAccount class. Use a static data me

ID: 3762200 • Letter: S

Question

SavingsAccount class program

Create a SavingsAccount class.

Use a static data member annualInterestRate to store the annual interest rate for each of the savers.

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.

Provide the appropriate constructors for the class

Write a main program to use the SavingsAccount class.

Create an array of 5 SavingsAccount objects. Each element of the array should be initialized with balances of $2,000, $4,000, $8,000, $16,000 and $32,000 respectively.

Set the annualInterestRate static data member to 3 percent.

Calculate the monthly interest amount and print the interest rate and new balances for each of the SavingsAccount objects in the array.

Then set the annualInterestRate static data member to 4 percent, calculate the next month’s interest amount and print the interest rate and new balances for each of the SavingsAccount objects in the array.

I'm having a problem with the second part of the program at the with the error at the "[i]"... any help would be appreciated!!
cout << setw(10) << savingAccounts[i].get_balance() << " " << setw(10) << savingAccounts[i].get_balance() << endl;

Heres what I got so far....

#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 savingAccounts[5]={2000,4000,8000,16000,32000};
   // I think that here is the place that I'm having the problem

SavingsAccount::modifyInterestRate(0.03);
cout << "Saver 1 Balance Saver 2 Balance " << endl;
cout << setw(10) << savingAccounts[i].get_balance() << " " << setw(10) << savingAccounts[i].get_balance() << endl;
for(int i=1; i<12; i++)
{
savingAccounts[i].calculateMonthlyInterest();
savingAccounts[i].calculateMonthlyInterest();
cout << setw(10) << savingAccounts[i].get_balance() << " " << setw(10) << savingAccounts[i].get_balance() << endl;
}
SavingsAccount::modifyInterestRate(0.04);
system("pause");

return 0;
}

Explanation / Answer

Pl. check following

#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 savingAccounts[5]={2000,4000,8000,16000,32000};
// I think that here is the place that I'm having the problem
SavingsAccount::modifyInterestRate(0.03);
int i=0;
cout << "Saver 1 Balance Saver 2 Balance " << endl;
cout << setw(10) << savingAccounts[i].get_balance() << " " << setw(10) << savingAccounts[i].get_balance() << endl;
for(int i=1; i<5; i++)
{
savingAccounts[i].calculateMonthlyInterest();
savingAccounts[i].calculateMonthlyInterest();
cout << setw(10) << savingAccounts[i].get_balance() << " " << setw(10) << savingAccounts[i].get_balance() << endl;
}
SavingsAccount::modifyInterestRate(0.04);
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote