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.



Answer :

The program to create a SavingsAccount class is illustrated below.

How to convey the information?

The program goes thus:

Code to be Copied:

SavingsAccount.h

#pragma once

#ifndef SAVINGS_H

#define SAVINGS_H

//SavingsAccount class declaration

class SavingsAccount

{

//declare data members

private:

//set annualInterestRate to 0.0 default value

static double annualInterestRate;

double savingsBalance;

public:

//set the balance

void setBalance(double);

//modify interest rates

static void modifyInterestRate(double);

//retruns total balance with interest

double calculateMonthInt();

};

#endif

SavingsAccount.cpp

//include required header files

#include<iostream>

#include"SavingsAccount.h"

using namespace std;

//set the annualInterestRate to 0

double SavingsAccount::annualInterestRate = 0;

//static funtion modify interest rate

void SavingsAccount::modifyInterestRate(double iRate)

{

annualInterestRate = iRate;

}

//set the balance

void SavingsAccount::setBalance(double bal)

{

savingsBalance = bal;

}

//calculating savings balance with monthly interest

double SavingsAccount::calculateMonthInt()

{

double monthInt = 0;

monthInt += savingsBalance*annualInterestRate / 12;

return savingsBalance += monthInt;

}

DriverProgram.cpp

//include required header files

#include<iostream>

#include "SavingsAccount.h"

using namespace std;

//main methods

int main()

{

//delcare class objects

SavingsAccount saver1, saver2;

//setter functions of balance

saver1.setBalance(2000.00);

saver2.setBalance(3000.00);

//Setting annual interset 0.03 to static variable

saver1.modifyInterestRate(0.03);

//finding the balance in saver1 and saver2 account

cout << "Balance of saver1 and saver2 on 3% interest Rate\n";

cout << "--------------------------------------------------\n";

cout << "Balance of saver1 = " << saver1.calculateMonthInt()

<< endl;

cout << "Balance of saver2 = " << saver2.calculateMonthInt()

<< endl << endl;

//Setting annual interset 0.04 to static variable

saver1.modifyInterestRate(0.04);

cout << "Balance of saver1 and saver2 on 4% interest Rate\n";

cout << "---------------------------------------------------\n";

cout << "New Balance of saver1 = " << saver1.calculateMonthInt() << endl;

cout << "New Balance of saver2 = " << saver2.calculateMonthInt() << endl<<endl;

return 0;

}

Learn more about program on:

https://brainly.com/question/26642771

#SPJ1