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

I am having a problem doing the second part of this program... 1) Create a Savin

ID: 3762009 • Letter: I

Question

I am having a problem doing the second part of this program...

1) 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 2) 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.

The code I have so far is

#include <iostream>

using namespace std;

class SavingsAccount

{

public:

SavingsAccount(){}

SavingsAccount(int value);

~SavingsAccount(){}

static float annualInterestRate;

void calculateMonthlyInterest();

static void modifyIntererestRate(float value);

float GetBalance() const { return savingsBalance; }

private:

float savingsBalance;

};

SavingsAccount::SavingsAccount(int value)

{

savingsBalance = value;

}

float SavingsAccount::annualInterestRate = 0;

void SavingsAccount::calculateMonthlyInterest()

{

savingsBalance += ((savingsBalance * annualInterestRate) / 12);

}

void SavingsAccount::modifyIntererestRate(float value)

{

annualInterestRate = value;

}

int main()

{

SavingsAccount saver1(2000.00);

SavingsAccount saver2(3000.00);

SavingsAccount::modifyIntererestRate(3);

saver1.calculateMonthlyInterest();

cout << "Saver 1 Savings Balance: $" << saver1.GetBalance() << endl;

saver2.calculateMonthlyInterest();

cout << "Saver 2 Savings Balance: $" << saver2.GetBalance() << endl;

cout << endl;

// I'm having a problem setting up the array

Explanation / Answer

Instead of

SavingsAccount saver1(2000.00);

SavingsAccount saver2(3000.00);

use the below code

//creating an array of SavingsAccount objects
SavingsAccount savingAccounts[5]={2000,4000,8000,16000,32000};

//you can access the array member as savingAccounts[i] where i can be 0,1,2,3,4