Question: In this lab you will define two derived classes of the BankAccount class provided: a checking account and a savings account class. The basic BankAccount

In this lab you will define two derived classes of the BankAccount class provided: a checking account and a savings account class. The basic BankAccount class provides the basic functionality of a bank account, such as withdrawal and deposit. The child (derived) classes implement the specific features of each type of account.

The Savings account:

This class must add interest rate as a feature. The interest will be set in the class constructor and the amount earned will be calculated by the monthlyProc function when the user asks for a statement. The amount earned should be added to the balance.

Redefine the withdraw function here to check if there is enough money before the withdrawal is performed by the base class function. It must make sure the balance in the account doesn't fall below zero.

The printStatement function calls monthlyProc to calculate the interest earned, and prints a statement that must include the balance in the account, the interest earned and the number of withdrawals and deposits made that month. Also, reset the number of withdrawals and deposits after printing the statement.

The Checking Account:

The Checking account class will manage the fees. After the first 5 withdrawals (which are free), there is a pre-defined fee that needs to be subtracted from the balance for each subsequent withdraw. The fee is set by the constructor and used to calculate the total fee amount.

Redefine the withdraw function here to check if there is enough money before the withdrawal is performed by the base class function. It must make sure the balance in the account doesn't fall below zero.

The printStatement function calls the monthlyProc to calculate the total fee amount, then print a statement including the balance in the account, the fee and the number of withdrawals and deposits made that month. Also, reset the number of withdrawals and deposits after printing the statement.

The following is provided:

BankAccount.h: The specification of the base bank account class.

main.cpp that you can use to test your classes.

#ifndef BankAccount_h

#define BankAccount_h

class BankAccount

{

private:

virtual void monthlyProc() = 0;

protected:

double amount;

int withdrawals, deposits;

public:

BankAccount(double amt)

{

amount = amt;

withdrawals = deposits = 0;

}

virtual void withdraw(double amt)

{

amount -= amt;

withdrawals++;

}

virtual void deposit(double amt)

{

amount += amt;

deposits++;

}

virtual void printStatement() = 0;

};

#include

#include "Savings.h"

#include "Checking.h"

int main(int argc, const char * argv[]) {

Checking checking(1000, .5);

Savings savings(5000, .1);

char acct, action;

double amt;

do {

do {

std::cout << "(C)hecking OR (S)avings \t => ";

std::cin >> acct;

std::cout << "(d)deposit \t (w)ithdraw \t (p)rint statement => ";

std::cin >> action;

std::cout << "Enter amount => ";

std::cin >> amt;

switch (acct)

{

case 'c':

case 'C':

switch(action)

{

case 'd':

case 'D':

checking.deposit(amt);

break;

case 'w':

case 'W':

checking.withdraw(amt);

break;

case 'p':

case 'P':

checking.printStatement();

break;

default:

std::cout << "Invalid action ";

}

break;

case 's':

case 'S':

switch(action)

{

case 'd':

case 'D':

savings.deposit(amt);

break;

case 'w':

case 'W':

savings.withdraw(amt);

break;

case 'p':

case 'P':

savings.printStatement();

break;

default:

std::cout << "Invalid action ";

}

}

std::cout << "Continue? (y/n) : ";

std::cin >> action;

} while (action == 'y' || action == 'Y');

checking.printStatement();

savings.printStatement();

std::cout << "Quit program? (y/n) : ";

std::cin >> action;

} while (action == 'n'|| action == 'N');

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!