Lab 4 - A Bank Account

Due - March 1/2, 2004

In this lab, you will write a program that simulates a bank account. Your program should have two functions, a function to deposit money and a function to withdraw money. Your deposit function should take as input an amount to be deposited and the current balance. The function should add the amount to be deposited to the current balance, and return the new balance. Your withdraw function should take as input the current balance and the amount to be withdrawn, and return the new balance. This function will use conditions as follows:
  1. the amount to be withdrawn must be between $0 and $300 -- if it is not, you should print a message that indicates that the desired withdrawl amount is inappropriate and no money is deducted
  2. if the amount to be withdrawn is larger than the current balance, an overdrawn fee of $3.50 should be deducted from the account (in this case, no additional amount should be deducted and a message should be printed for the user)
  3. in all other cases, the amount to be withdrawn should be deducted from the account, and the new balance returned
Think carefully about the test cases you generated for your warmup assignment. A test case will consist of a series of calls to the deposit and withdraw functions and should demonstrate that at least one feature of your functions works properly. You should have a test case to test each feature of your functions. An example test case to determine whether your overdrawn fee is deducted properly would be as follows:
Testing overdrawn fee
---------------------
deposit $500
withdraw $300
print the balance (should be $200)
withdraw $300 (should see a message indicating overdrawn fee is being deducted)
print the balance (should be $196.50)

  1. Make sure that each function is well documented. Your documentation should specify the type and role of the input paramaters and ouput.
  2. Make sure a lab assistant (Dianne or I) has seen your program run.
  3. Copy and paste the output of your program to the bottom of your program itself. Make sure the output is a comment. That means, put a /* before the output and a */ after the output.

Sami Rollins