→This assignment is due by Tuesday, September 24, 2024, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
Jump To: Rubric Submission
In this assignment, we will combine everything we've learned so far with a focus on conditionals, loops, and functions that accept pointer parameters.
Overview
For this assignment, your job is to create the logic of an Automated Teller Machine. The user will be presented with a menu of options. When the user selects an option, the corresponding function will need to be called.
It may be tempting to store currency as a single floating point value. However, due to precision errors with floats we can sometimes lose money as the errors compound. Instead, it is not uncommon to store dollars and cents separately as two separate integers. This will be the approach that we take.
The Specifics
The following functions must be implemented. Here, the input corresponds to the expected parameters and the output corresponds to the expected return value.
-
- Function Name: start_atm
- Input: None
- Output: None
- Description: Contains the logic to display the menu to the user, prompts user for selection, validate user's selection, and calls the corresponding action.
-
- Function Name: print_menu
- Input: None
- Output: None
- Description: Prints the menu to the user. The menu should contain four options: (1) Print balance (2) Deposit (3) Withdrawal (Q) Quit.
-
- Function Name: get_user_selection
- Input: None
- Output: Character representing user's choice
- Description: Prompts the user to input a value corresponding to the menu selections and returns the user's choice.
-
- Function Name: print_balance
- Input:
- An
int
pointer corresponding to the user's current dollar amount - An
int
pointer corresponding to the user's current cent amount
- An
- Output: None
- Description: Pretty prints the current balance to the screen with a dollar sign and two decimal places along with a friendly message.
-
- Function Name: deposit_money
- Input:
- An
int
pointer corresponding to the user's current dollar amount - An
int
pointer corresponding to the user's current cent amount
- An
- Output: None
- Description: Prompts the user to enter an amount to deposit. Validates both amounts are positive. If the amounts are positive, then modifies the user's balance appropriately.
-
- Function Name: withdraw_money
- Input:
- An
int
pointer corresponding to the user's current dollar amount - An
int
pointer corresponding to the user's current cent amount
- An
- Output:
- Description: Prompts the user to enter an amount to withdraw. Validates both amounts are positive. If the amounts are positive and there is enough money in the account to withdraw, then modifies the user's balance.
With this structure, our main.cpp
file will contain nothing more than:
int main() {
start_atm();
return 0;
}
start_atm()
function. A sample run of the program is below with user input italicized for emphasis:
Welcome to the Infinite ATM!
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 1
You currently have $0.00.
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 2
How many dollars would you like to deposit? 4
How many cents would you like to deposit? 50
Thank you for depositing $4.50!
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 1
You currently have $4.50.
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 3
How many dollars do you wish to withdraw? 3
How many cents do you wish to withdraw? 0
Here is your $3.00!
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 1
You currently have $1.50.
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 3
How many dollars do you wish to withdraw? 3
How many cents do you wish to withdraw? 0
We are sorry, you have insufficient reserves in your treasure store.
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 3
How many dollars do you wish to withdraw? -3
How many cents do you wish to withdraw? 0
We are sorry, we are not in the business of giving away money.
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 3
How many dollars do you wish to withdraw? 1
How many cents do you wish to withdraw? -10
We are sorry, we are not in the business of giving away money.
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 2
How many dollars do you wish to deposit? -5
How many cents do you wish to deposit? 0
It seems you are trying to make a withdrawal. Perhaps try that instead?
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 7
It is not clear what you are trying to do.
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 2
How many dollars do you wish to deposit? 0
How many cents do you wish to deposit? 75
Thank you for depositing $0.75!
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 1
You currently have $2.25.
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 3
How many dollars do you wish to withdraw? 0
How many cents do you wish to withdraw? 221
Here is your $2.21!
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: 1
You currently have $0.04.
Please make a selection:
(1) Print Current Balance
(2) Deposit
(3) Withdraw
(Q) Quit
Choice: Q
Thanks for coming!
You do not need to match the text of the prompts exactly but you must match the functionality presented above.
Functional Requirements
- Do not use global variables! If you are using a global variable in multiple functions, then you should be passing that variable into the function. If you use global variables, you will lose points so get out of the global variable shortcut habit.
- All functions must be placed in a separate file named
atmFunctions.h
andatmFunctions.cpp
. - Do not use the
goto
command. You will lose points for usinggoto
. You must structure your conditionals, loops, and functions properly to receive full credit. - Ensure the cents are always printed with two decimal values.
- Be sure to handle the cents overflow/underflow correctly. Review the example output above for sample.
Grading Rubric
Your submission will be graded according to the following rubric:
Points | Requirement Description |
0.5 | Submitted correctly by Tuesday, September 24, 2024, 11:59 PM |
0.5 | Project builds without errors nor warnings. |
2.0 | Best Practices and Style Guide followed. |
0.5 | Program follows specified user I/O flow. |
0.5 | Public and private tests successfully passed. |
2.0 | Fully meets specifications. |
6.00 | Total Points |
Submission
Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available.
Zip together your main.cpp, atmFunctions.h, atmFunctions.cpp, Makefile
files and name the zip file A2.zip
. Upload this zip file to Canvas under A2.
→This assignment is due by Tuesday, September 24, 2024, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←