The program to create a SavingsAccount class is illustrated below.
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