Task writing the software for an ATM using functions to siml
Task: writing the software for an ATM using functions to simlify as much as possible. This is for C++. If you could also send pics of the output as well. Please help, thank you very much for your time.
The program should prompt the user for their PIN (Personal Identification Number). For the purposes of this homework, the PIN 7007 must be accepted. If the user inputs an unacceptable PIN, an appropriate error message should be displayed and the PIN prompted for again.
Once an acceptable PIN has been entered, the program is to use the following menu:
Withdrawal
Deposit
Check Balances
Transfer
Quit
The user has a checking account and a savings account. Both accounts have an initial balance of $100 dollars. The balance should change by the appropriate amount depending on the type of transaction used (for example, withdrawing $5 from the checking account should subtract $5 from the checking balance).
Check Balances should print the balances the user has in the two accounts (i.e. checking and savings).
Withdrawal amounts should be in multiples of $5 only. Any other amount is an error.
If a withdrawal or deposit transaction is requested, the following menu should be used:
1. Checking 2. Savings 3. Cancel
After the response is entered, the user should be prompted for the amount of money to use and the appropriate action should be taken. (note: the system is smart enough to know that if the user chooses from Checking the money will be moved to their Savings account and vice versa). Transfer amounts are not restricted to increments of $5, they can be any valid amount of money.
The program should return to the main menu after each transaction and continue until option 5 (Quit) has been chosen.
The program is expected to do error checking. For example, you should not be allowed to withdraw $100 from an account that only has $5 in it. In this case, an appropriate error message should be printed, and the user asked if they want to enter a different withdrawal amount, or exit the withdrawal menu. The program should not exit until the user has asked to quit from the main menu. The user should always have a way to get back to this menu to quit, hence the third choice on the withdrawal and deposit menu (Cancel).
Solution
PROGRAM CODE:
#include <iostream>
#include <math.h>
using namespace std;
class BankApplication
{
private:
int PIN;
string name;
double checkingAccount;
double savingsAccount;
public:
BankApplication(string c_name, int c_PIN)
{
name = c_name;
PIN = c_PIN;
checkingAccount = 0;
savingsAccount = 0;
}
int getPIN()
{
return PIN;
}
string getName()
{
return name;
}
void withdraw(int option, double amount)
{
if(fmod(amount, 5) == 0)
{
if(option == 1)
{
if(amount > checkingAccount)
{
cout<<\"Insufficient balance\"<<endl;
return;
}
checkingAccount -= amount;
}
else
{
if(amount > savingsAccount)
{
cout<<\"Insufficient balance\"<<endl;
return;
}
savingsAccount -= amount;
}
}
else cout<<\"Withdrawal amount should be in multiples of 5\"<<endl;
}
void deposit(int option, double amount)
{
if(option == 1)
checkingAccount += amount;
else savingsAccount += amount;
}
double getSavingsBalance()
{
return savingsAccount;
}
double getCheckingBalance()
{
return checkingAccount;
}
void transfer(int option, double amount)
{
if(option == 1)
{
if(amount > checkingAccount)
{
cout<<\"Insufficient balance\"<<endl;
return;
}
checkingAccount -= amount;
savingsAccount += amount;
}
else
{
if(amount > savingsAccount)
{
cout<<\"Insufficient balance\"<<endl;
return;
}
checkingAccount += amount;
savingsAccount -= amount;
}
}
void quit()
{
exit(0);
}
int subMenu()
{
int choice;
cout<<\"\ 1. Checking\ 2. Savings\ 3. Cancel\ \";
cout<<\"Enter your choice: \";
cin>>choice;
if(choice > 0 && choice<4)
return choice;
else {
cout<<\"Invalid choice !\ \";
subMenu();
}
}
void menu()
{
int option;
cout<<\"\ 1. Withdrawal\ 2. Deposit\ 3. Check Balances\ 4. Transfer\ 5. Quit\"<<endl;
cout<<\"Enter your choice: \";
cin>>option;
double amount;
int ch;
switch(option)
{
case 1: ch = subMenu();
cout<<\"\ Enter amount: \";
cin>>amount;
withdraw(ch, amount);
break;
case 2: ch = subMenu();
cout<<\"\ Enter amount: \";
cin>>amount;
deposit(ch, amount);
break;
case 3: cout<<\"\ Savings Balance: $\"<<getSavingsBalance()<<endl<<\"Checking Balance: $\"<<getCheckingBalance()<<endl;
break;
case 4: ch = subMenu();
cout<<\"\ Enter amount: \";
cin>>amount;
transfer(ch, amount);
break;
case 5:exit(0);
default: cout<<\"Invalid choice !\ \";
}
menu();
}
};
int main() {
//Login to the application is handled from main function
//All other functions are performaed by the BankApplication
BankApplication application(\"John Doe\", 7007);
int pin = 0000;
cout<<\"Welcome \" <<application.getName()<<\"!\"<<endl;
cout<<\"Enter your pin: \";
cin>>pin;
while(application.getPIN() != pin)
{
cout<<\"\ Invalid PIN !\"<<endl;
cout<<\"Enter your PIN again: \";
cin>>pin;
}
application.menu();
return 0;
}
OUTPUT:



