CECS 282
LAB ASSIGNMENT 2
Assigned date: 9/3
Due date:  Tuesday 9/10
40 points


1. [10 points] Implement a class Account. An account has a balance, functions to add and withdraw money, and a function to query the current balance. Charge $20 penalty if an attempt is made to withdraw more money than available in the account.
Test your Account class by using the following main function.

int main()
{
   Account my_account(100);     // Set up my account with $100
   my_account.deposit(50);
   my_account.withdraw(175);   // Penalty of $20 will apply
   my_account.withdraw(25);

   cout << "Account balance: " << my_account.get_balance() << "\n";
  
   my_account.withdraw(my_account.get_balance());  // withdraw all
   cout << "Account balance: " << my_account.get_balance() << "\n";
 
   return 0;  
}

2.[10 points] Enhance the Account class to compute the interest on the current balance. An account has initial balance of $10,000.00, and 6% percent annual interest is compounded monthly until  the investement is double.
Write a main function to determine the number of months to double the initial investment. Create a menu to allow the user to enter the initial investement and the annual interest rate.

3.[20 points] Implement a class Bank. This bank has two objects, checking and savings of type Account that was developed in the problem 2. Implement four member functions:

     deposit(double amount, string account)
     withdraw(double amount, string account)
     transfer(double amount, string account)
     print_balance()

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

Test your program by using the main function below.

int main()
{
Bank my_bank;
cout << "Inital bank balances: \n";
my_bank.print_balances(); /* set up empty accounts */

cout << "Adding some money to accounts: \n";
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.\n";
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.\n";
my_bank.transfer(900,"C");
my_bank.print_balances();

cout << "trying to transfer $900 from Savings.\n";
my_bank.transfer(900,"S");
my_bank.print_balances();

return 0;
}

Grading