In: Computer Science
class BankAccount
{
public:
double balance = 0;
int numOfDeposits = 0;
int numOfWithdraws = 0;
double interestRate = 0;
double annualInterest = 0;
double monSCharges = 0;
double amount = 0;
double monInterest = 0;
//constructor accepts arguments for balance and annual interest
rate
BankAccount(double bal, double intrRate);
//sets amount
virtual void setAmount(double myAmount);
//method to add to balance and increment number of
deposits
virtual void deposit(double amountIn);
//method to negate from balance and increment number of
withdrawals
virtual void withdraw(double amount);
//updates balance by calculating monthly interest earned
virtual double calcInterest();
//subtracts services charges calls calcInterest method sets
number of withdrawals and deposits
//and service charges to 0
virtual void monthlyProcess();
//returns balance
virtual double getBalance();
//returns deposits
virtual double getDeposits();
//returns withdrawals
virtual double getWithdraws();
};
and_Keyword the subclass class SavingsAccount : public
BankAccount
{
//sends balance and interest rate to BankAccount constructor
public:
SavingsAccount(double b, double i);
//determines if account is active or inactive based on a min
acount balance of $25
virtual bool isActive();
//checks if account is active, if it is it uses the superclass
version of the method
virtual void withdraw();
//checks if account is active, if it is it uses the superclass
version of deposit method
virtual void deposit();
//checks number of withdrawals adds service charge
void monthlyProcess() override;
};
//.cpp file code:
#include "snippet.h"
BankAccount::BankAccount(double bal, double intrRate)
{
balance = bal;
annualInterest = intrRate;
}
void BankAccount::setAmount(double myAmount)
{
amount = myAmount;
}
void BankAccount::deposit(double amountIn)
{
balance = balance + amountIn;
numOfDeposits++;
}
void BankAccount::withdraw(double amount)
{
balance = balance - amount;
numOfWithdraws++;
}
double BankAccount::calcInterest()
{
double monRate;
monRate = interestRate / 12;
monInterest = balance * monRate;
balance = balance + monInterest;
return balance;
}
void BankAccount::monthlyProcess()
{
calcInterest();
numOfWithdraws = 0;
numOfDeposits = 0;
monSCharges = 0;
}
double BankAccount::getBalance()
{
return balance;
}
double BankAccount::getDeposits()
{
return numOfDeposits;
}
double BankAccount::getWithdraws()
{
return numOfWithdraws;
}
SavingsAccount::SavingsAccount(double b, double i) :
BankAccount(b, i)
{
}
bool SavingsAccount::isActive()
{
if (balance >= 25)
{
return true;
}
return false;
}
void SavingsAccount::withdraw()
{
if (isActive() == true)
{
BankAccount::withdraw(amount);
}
}
void SavingsAccount::deposit()
{
if (isActive() == true)
{
BankAccount::deposit(amount);
}
}
void SavingsAccount::monthlyProcess()
{
if (numOfWithdraws > 4)
{
monSCharges++;
}
}
NOTE:If my answer helped you,please like my answer. THANK YOU!!