Answer to Question #326587 in C++ for Fazishima

Question #326587

Create a SavingsAccount class. Use a static data member annualInterestRate

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 month's interest and print the new balances for

each of the savers.


1
Expert's answer
2022-04-10T06:27:16-0400
#include<iostream>
#include<string>
using namespace std;

class SavingsAccount
{
	static float annualInterestRate;
	float savingsBalance;
public:
	SavingsAccount(float _savingsBalance=0):savingsBalance(_savingsBalance){}
	float calculateMonthlyInterest()
	{
		savingsBalance+=savingsBalance*annualInterestRate / 12;
		return savingsBalance*annualInterestRate / 12;
	}
	static void modifyInterestRate(float val)
	{
		annualInterestRate = val;
	}
	void Print()
	{
		cout << "\nsavingsBalance = " << savingsBalance;
	}
};


float SavingsAccount::annualInterestRate = 0;


int main()
{
	SavingsAccount saver1(2000);
	SavingsAccount saver2(3000);
	saver1.modifyInterestRate(0.03);
	cout <<"\nsaver1.calculateMonthlyInterest() = "<< saver1.calculateMonthlyInterest();
	cout << "\nsaver2.calculateMonthlyInterest() = " << saver2.calculateMonthlyInterest();
	saver1.Print();
	saver2.Print();
	saver1.modifyInterestRate(0.04);
	cout << "\nsaver1.calculateMonthlyInterest() = " << saver1.calculateMonthlyInterest();
	cout << "\nsaver2.calculateMonthlyInterest() = " << saver2.calculateMonthlyInterest();
	saver1.Print();
	saver2.Print();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS