CMSC104 Spring 2014
Programming Project 2
Bank Account
Out: Wednesday, April 9
Due: Wednesday, April 16, before 11:59 p.m.
The Objective
This project is designed to give you practice working with switch statements and functions. It will also give you more practice working with while loops.
The Background
Most people store their money in a checking account. There are two basic operations performed on the checking account. One operation is to deposit money into the account and the other is to make a withdrawal from the account.
The Task
Your job is to write a program that will simulate the behavior of a checking account. Your program should accept a beginning balance from the user and then display a menu with four options. The menu should have the four options shown in the sample output below. The functions you will write, in addition to the main function, are:
- void print_greeting (void); - This function prints an explanation of the program to the user. You should assume the user knows nothing about the program and give a detailed explanation.
- void print_menu (void); - This function displays the menu to the screen.
- float get_positive_value (void); - This function gets a positive (greater than 0) value from the user. It should error check the user input to make sure the value is greater than 0, and loop until the user enters a proper value. (We written this kind of loop many times during the term, so refer to old lecture slides.) It takes no arguments and returns the value entered by the user. You should use this function to get the beginning balance from the user. You should also use it to get the amount to withdraw or deposit.
- float withdrawal (float balance, float withdrawal_amt); - This function takes the current balance and the amount to withdraw. It returns the new balance after the withdrawal is made.
- float deposit (float balance, float deposit_amt); - This function takes the current balance and the amount to be deposited as arguments. It returns the new balance after the deposit is made.
- void print_receipt (int total_withdrawals, int total_deposits, float beg_balance, float balance); - This function prints an account summary to the screen. It should list the total number of withdrawals, the total number of deposits, the beginning balance and the ending balance. It does not have to match the sample output exactly.
More Details
- You must use the above function prototypes EXACTLY as they have been given to you. You may not change them in any way.
- You should also use symbolic constants (we'll discuss
these in class on Wednesday) for the menu options in the
switch statement:
#define WITHDRAWAL 1 #define DEPOSIT 2 #define SUMMARY 3 #define QUIT 4
- If the balance in the checking account goes below zero after making a withdrawal or deposit, you should print a message to the user stating that the balance is negative. You do not have to prevent the balance from going below zero, you should simply print a warning when it happens.
Hints
Note that functions like withdrawal()
and
deposit()
update the balance and return it.
Recall that function parameters are local variables, so just
updating the balance
parameter variable inside
these functions will not change the balance in the calling
function. So, the function that calls withdrawal()
and
deposit()
(probably main()
) must
take the return value and assign it back into the balance
variable it is maintaining.
Sample Output
linux3[1]% gcc -ansi -Wall proj3.c linux3[2]% a.out [Your greeting goes here.] Please enter the beginning balance: 1000.00 1) Make a Withdrawal 2) Make a Deposit 3) Display Account Summary 4) Quit Selection: 1 Enter the amount to withdraw: 500.00 1) Make a Withdrawal 2) Make a Deposit 3) Display Account Summary 4) Quit Selection: 1 Enter the amount to withdraw: 100.00 1) Make a Withdrawal 2) Make a Deposit 3) Display Account Summary 4) Quit Selection: 3 ---------------------------------------------------- Account Summary Beginning balance: $1000.00 Ending balance: $400.00 Total number of withdrawals: 2 Total number of deposits: 0 ---------------------------------------------------- 1) Make a Withdrawal 2) Make a Deposit 3) Display Account Summary 4) Quit Selection: 2 Enter the amount to deposit: 500.00 1) Make a Withdrawal 2) Make a Deposit 3) Display Account Summary 4) Quit Selection: 3 ---------------------------------------------------- Account Summary Beginning balance: $1000.00 Ending balance: $900.00 Total number of withdrawals: 2 Total number of deposits: 1 ---------------------------------------------------- 1) Make a Withdrawal 2) Make a Deposit 3) Display Account Summary 4) Quit Selection: 1 Enter the amount to withdraw: 1000.00 ********* WARNING: You have a negative account balance ********* 1) Make a Withdrawal 2) Make a Deposit 3) Display Account Summary 4) Quit Selection: 3 ---------------------------------------------------- Account Summary Beginning balance: $1000.00 Ending balance: $-100.00 Total number of withdrawals: 3 Total number of deposits: 1 ---------------------------------------------------- 1) Make a Withdrawal 2) Make a Deposit 3) Display Account Summary 4) Quit Selection: 4 linux3[3]%
Submitting the Program
Here is a sample submission command:
linux3[4]% submit cmsc104_cmarron proj2 proj2.c
To verify that your project was submitted, you can execute the
following command at the Unix prompt. It will show the file that you
submitted in a format similar to the Unix ls
command.
linux3[5]% submitls cmsc104_cmarron proj2