Question: Implement a class Bank. This bank has two objects, checking and savings of type Account that was developed in Lab 2. Implement four member functions:

Implement a class Bank. This bank has two objects, checking and savings of type Account that was developed in Lab 2. Implement four member functions:

void deposit(double amount, string account);

void withdraw(double amount, string account);

void transfer(double amount, string account);

void print_balances();

Here the account string is S or C. For deposit or withdrawal, it indicates which account is affected. For a transfer it indicates the account from which the money is taken; the money is automatically transferred to the other account.

The class Bank should look like:

class Bank { public: Bank();

Bank(double checking_amount, double savings_amount);

void deposit(double amount, string account);

void withdraw(double amount, string account);

void transfer(double amount, string account);

void print_balances();

private: Account checking;

Account savings;

};

Include the iomanip library, for print_balances()

void Bank::print_balances()const {

cout << "Savings account balance: $"

<< fixed << setprecision(2)

<< setw(8) << savings.get_balance() << endl

<< "Checking account balance: $"

<< setw(8) << checking.get_balance()

<< endl << endl; }

Use the following main as a driver program:

int main() {

Bank my_bank; // set up empty accounts

cout << "Inital bank balances: " << endl;

my_bank.print_balances();

cout << "Adding some money to accounts: " << endl;

my_bank.deposit(1000, "S"); // deposit $1000 to savings

my_bank.deposit(2000, "C"); // deposit $2000 to checking

my_bank.print_balances();

cout << "Taking out $1500 from checking,and moving $200 from";

cout << " savings to checking." << endl;

my_bank.withdraw(1500, "C"); // withdraw $1500 from checking

my_bank.transfer(200, "S"); // transfer $200 from savings

my_bank.print_balances();

cout << "Trying to transfer $900 from Checking." << endl;

my_bank.transfer(900,"C");

my_bank.print_balances();

cout << "trying to transfer $900 from Savings." << endl;

my_bank.transfer(900,"S");

my_bank.print_balances();

return 0; }

Note: You can keep it all in one file or separate out Account class from Bank class

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!