Problem Description In this assignment, you will be writing a C++ program for AT
ID: 3722728 • Letter: P
Question
Problem Description
In this assignment, you will be writing a C++ program for ATM machines to serve multiple customers. Each customer has a Personal Identification Number (PIN), and there are two types of customers. Type 1 customers have an odd PIN number and type 2 customers have an even PIN number. A type 2 customer will be charged $5 if the amount requested makes the balance fall below $500. A customer can process multiple withdrawals in a session. To end a session, the customer will enter a -1.
Input
At the beginning of the program, the customer’s balance is entered into the system.
Each customer will enter her/his PIN number and the amount they want to withdraw. The balance in the account must always be enough to cover the withdrawal plus any fees. If a fee is to be charged for a withdrawal amount, and there is not enough in the balance to cover the and the withdrawal amount, it should print, "Not enough money in your account to pay the fee!”. See the Sample Runs for an example.
All PIN numbers are between 1000 and 9999, inclusive. If an entered PIN number is out of the range, then the program shall display a message and ask the customer to enter a PIN again until a valid PIN number is entered. Once a valid pin is entered, the program will run until the user enters a -1 to quit, or if the balance is zero.
The amount a customer may request is between $20 and $1000, inclusive. If an entered amount is out of the range, the program shall display a message and ask the customer to enter another amount again until a valid amount is entered. The withdrawal amount must be divisible by 5, as the smallest denomination that the ATM dispenses is a $5 bill. The balance in the account must be enough to cover the withdrawal.
If a type 2 customer enters a withdrawal amount that makes the balance fall below $500, the program shall display a message to warn the customer of the $5 fee. The balance in the account must be enough to cover the withdrawal and the fee. If there is not enough money in the balance, the withdrawal will not be processed.
In all cases, the withdrawal amount must not exceed the balance.
Output
After processing a valid request, the program shall display the amount requested, the fee if applicable, and the bills the customer is receiving. The ATM can deliver $20, $10, and $5 bills, and the machine will deliver the maximum possible number of $20 bills, one $10 bill if the remaining is at least 10, and one $5 bill if the remaining is at least 5. The customer enters a -1 to quit. The program shall display messages to assist customers to use the ATM. See the sample run later for details and formats of the output.
Pseudocode
Read in balance
Read in and validate PIN
Read in amount to be withdrawn, loop until -1
Validate withdrawl amount
If type 2 customer
Print Fee message
If not enough money with fee, print error
If there is enough money
Subtract withdrawl from amount
Subtract fee if type 2
Print withdrawl amount
Dispense money
Read in amount to be withdrawn
Notes
As a minimal output and to receive credit for doing program 2, your program MUST get the correct output for Test Case 1.
Each sentinel-controlled loop must be primed.
Follow the output format exactly.
Remember you cannot have magic numbers in your program.
Sample run (Test Case 1) – responses in red are the user’s typed responses
Sample run (Test Case 2)
Sample run (Test Case 3)
Enter your balance: 200
Enter your PIN: 1100
Your balance is $200.
Enter the amount to be withdrawn, -1 to quit: 300
Invalid amount: 300.
Your balance is $200.
Enter the amount to be withdrawn: 400
Invalid amount: 400.
Your balance is $200.
Enter the amount to be withdrawn: 200
You are a type 2 customer, but the withdrawal
amount you requested makes your balance $0,
which is below the minimum balance required.
You will be charged $5.
Not enough in your account to cover the withdrawal and the fee!
Your balance is $200.
Enter the amount to be withdrawn, -1 to quit: 400
Invalid amount: 400.
Your balance is $200.
Enter the amount to be withdrawn: 100
You are a type 2 customer, but the withdrawal
amount you requested makes your balance $100,
which is below the minimum balance required.
You will be charged $5.
You requested $100.
You are receiving the following bills:
Number of $20 bills: 5
Number of $10 bills: 0
Number of $5 bills: 0
Your balance is $95.
Enter the amount to be withdrawn, -1 to quit: 200
Invalid amount: 200.
Your balance is $95.
Enter the amount to be withdrawn: 50
You are a type 2 customer, but the withdrawal
amount you requested makes your balance $45,
which is below the minimum balance required.
You will be charged $5.
You requested $50.
You are receiving the following bills:
Number of $20 bills: 2
Number of $10 bills: 1
Number of $5 bills: 0
Your balance is $40.
Enter the amount to be withdrawn, -1 to quit: -1
Thank you for banking with us, have a nice day!
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
class AutoTellerMachine { //Object to represent each customer who uses the ATM program
public:
void CreateNewAccount(string newUsername, string newPassword);
void AccountLogin(string loginUsername, string loginPassword);
void DepositMoney(double depositAmount);
void WithdrawMoney(double withdrawalAmount);
void SetAccountLogin(int setAccountLocation);
void SetLastMoneyMovement(int accountID, double amount);
void SetBeginningBalance(int accountID);
void SetLastOperation(int accountID, char userInput);
void AccountMenu();
int GetAccountLogin() const;
double GetLastMoneyMovement(int accountID) const;
double GetAccountBalance(int accountID) const;
double GetBeginningBalance(int accountID) const;
char GetLastOperation(int accountID) const;
string GetUsername(int accountID) const;
private:
int loggedInAccountLocation;
double accountBalance;
double beginningBalance;
double lastMoneyMovement;
char lastOperation;
string username;
string password;
};
AutoTellerMachine account;
vector<AutoTellerMachine> AccountList; //This vector allows for multiple accounts to be stored so that if more than one person uses the account, all information is retained
void AccountMenu();
void UserMenu();
void AutoTellerMachine:: SetAccountLogin(int setAccountLocation) {
loggedInAccountLocation = setAccountLocation;
return;
}
int AutoTellerMachine::GetAccountLogin() const {
return loggedInAccountLocation;
}
void AutoTellerMachine::CreateNewAccount(string newUsername, string newPassword) { //Adds the new information to the vector to give the account personalized info
int accountListSize = AccountList.size();
AccountList.at(accountListSize - 1).accountBalance = 0.0;
AccountList.at(accountListSize - 1).username = newUsername;
AccountList.at(accountListSize - 1).password = newPassword;
}
void AutoTellerMachine::AccountLogin(string loginUsername, string loginPassword) {
int accountListSize = AccountList.size();
bool successfulLogin = false;
int accountLocation = 0;
for(int i = 0; i < accountListSize; i++) {
if(loginUsername == AccountList.at(i).username) {
if(loginPassword == AccountList.at(i).password) {
successfulLogin = true;
accountLocation = i;
}
}
}
if(successfulLogin != true) {
cout << endl << "******** LOGIN FAILED! ********" << endl << endl;
UserMenu();
}
else if(successfulLogin == true) {
SetAccountLogin(accountLocation);
cout << endl << "Access Granted - " << AccountList.at(loggedInAccountLocation).username << endl;
AccountMenu();
}
return;
}
void AutoTellerMachine::DepositMoney(double depositAmount) {
AccountList.at(loggedInAccountLocation).accountBalance += depositAmount;
return;
}
void AutoTellerMachine::WithdrawMoney(double withdrawalAmount) {
AccountList.at(loggedInAccountLocation).accountBalance -= withdrawalAmount;
return;
}
double AutoTellerMachine::GetAccountBalance(int accountID) const {
return AccountList.at(loggedInAccountLocation).accountBalance;
}
void AutoTellerMachine::SetLastMoneyMovement(int accountID, double amount) {
AccountList.at(accountID).lastMoneyMovement = amount;
}
void AutoTellerMachine::SetBeginningBalance(int accountID) {
AccountList.at(accountID).beginningBalance = AccountList.at(loggedInAccountLocation).accountBalance;
}
void AutoTellerMachine::SetLastOperation(int accountID, char userInput) {
AccountList.at(accountID).lastOperation = userInput;
}
double AutoTellerMachine::GetLastMoneyMovement(int accountID) const {
return AccountList.at(accountID).lastMoneyMovement;
}
double AutoTellerMachine::GetBeginningBalance(int accountID) const {
return AccountList.at(accountID).beginningBalance;
}
char AutoTellerMachine::GetLastOperation(int accountID) const {
return AccountList.at(accountID).lastOperation;
}
string AutoTellerMachine::GetUsername(int accountID) const {
return AccountList.at(GetAccountLogin()).username;
}
void UserMenu() { //Implements a user interface that allows the user to make selections based on what they want to do
char userSelection;
string createUserId;
string createUserPass;
string usernameCheck;
string passwordCheck;
cout << "l -> Login" << endl;
cout << "c -> Create New Account" << endl;
cout << "q -> Quit" << endl << endl << ">";
cin >> userSelection;
if((userSelection == 'l') || (userSelection == 'L')) { //Checks to make sure the login is valid and if not, couts an error statement
cout << endl << "Please enter your user name: " << endl;
cin >> usernameCheck;
cout << "Please enter your password: " << endl;
cin >> passwordCheck;
account.AccountLogin(usernameCheck, passwordCheck);
}
else if((userSelection == 'c') || (userSelection == 'C')) { //Captures info for a new account
cout << endl << "Please enter your user name: " << endl;
cin >> createUserId;
cout << "Please enter your password: " << endl;
cin >> createUserPass;
AccountList.push_back(account); //This creates a new object in the vector to be filled with the information gathered
account.CreateNewAccount(createUserId, createUserPass);
cout << endl << "Thank You! Your account has been created!" << endl << endl;
UserMenu();
}
else if((userSelection == 'q') || (userSelection == 'Q')) { //Exits the entire program
cout << endl << "You selected quit!" << endl << endl;
}
else {
cout << endl << "Invalid selection." << endl;
UserMenu();
}
return;
}
void AutoTellerMachine::AccountMenu() { //This is a separate menu from the user menu because it deals with all options available to a logged in customer
char userInput;
double amountOfDeposit;
double amountOfWithdrawal;
cout << endl << "d -> Deposit Money" << endl; //This has a couple more options than indicated in our project overview, but I feel they make this a more useable program
cout << "w -> Withdraw Money" << endl;
cout << "r -> Request Balance" << endl;
cout << "z -> Logout" << endl;
cout << "q -> Quit" << endl;
cout << endl << ">";
cin >> userInput;
if((userInput == 'd') || (userInput == 'D')) { //Deposit function that changes the balance of the account user and sets the last money movement for later use
SetBeginningBalance(GetAccountLogin());
cout << endl << "Amount of deposit: " << endl;
cin >> amountOfDeposit;
SetLastMoneyMovement(GetAccountLogin(), amountOfDeposit);
SetLastOperation(GetAccountLogin(), userInput);
DepositMoney(amountOfDeposit);
AccountMenu();
}
else if((userInput == 'w') || (userInput == 'W')) { //Withdraw function makes sure that enough funds are present for the operation before removing money
cout << endl << "Amount of withdrawal: " << endl;
cin >> amountOfWithdrawal;
if(amountOfWithdrawal > GetAccountBalance(GetAccountLogin())) {
cout << endl << "******Insfficient Funds!*******" << endl;
}
else {
SetBeginningBalance(GetAccountLogin());
SetLastMoneyMovement(GetAccountLogin(), amountOfWithdrawal);
SetLastOperation(GetAccountLogin(), userInput);
WithdrawMoney(amountOfWithdrawal);
}
AccountMenu();
}
else if((userInput == 'r') || (userInput == 'R')) { //Simply prints the balance before the last transaction, what type and amount the last transaction was then the current balance
cout << endl << "Beginning balance: $" << fixed << setprecision(2) << GetBeginningBalance(GetAccountLogin()) << endl;
if(GetLastOperation(GetAccountLogin()) == 'd') {
cout << "Deposit amount: $" << fixed << setprecision(2) << GetLastMoneyMovement(GetAccountLogin()) << endl;
}
else if(GetLastOperation(GetAccountLogin()) == 'w') {
cout << "Withdrawal amount: $" << fixed << setprecision(2) << GetLastMoneyMovement(GetAccountLogin()) << endl;
}
cout << "Your balance is $" << fixed << setprecision(2) << GetAccountBalance(GetAccountLogin()) << endl;
AccountMenu();
}
else if((userInput == 'z') || (userInput == 'Z')) { //Allows the user to logout of their account and brings them back to the user menu so they can log in with a different account
cout << endl << "You have successfully logged out, " << GetUsername(GetAccountLogin()) << "!" << endl << endl;
UserMenu();
}
else if((userInput == 'q') || (userInput == 'Q')) { //Exits the entire program
cout << endl << "Thanks for banking with COP2513.F16, " << GetUsername(GetAccountLogin()) << "!" << endl;
}
else {
cout << endl << "Invalid selection." << endl;
AccountMenu();
}
return;
}
int main() {
cout << "Welcome to COP2513.F16’s ATM Machine" << endl << endl;
cout << "Please select an option from the menu below: " << endl << endl;
UserMenu();
}`
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.