In: Computer Science
Language C++!
In part 2, you will be focusing on allowing one of the four transactions listed below to be completed by the user on one of his accounts: checking or savings. You will include defensive programming and error checking to ensure your program functions like an ATM machine would. The account details for your customer are as follows:
Customer | Username | Password | Savings Account | Checking Account |
Robert Brown | rbrown | blue123 | $2500.00 | $35.00 |
For this report, update the C++ program that allows the account owner to complete one of the 5 functions of the ATM:
1 – Deposit (adding money to the account)
2 – Withdrawal (removing money from the
account)
3 – Balance Inquiry (check current balance)
4 – Transfer Balance (transfer balance from one account to
another)
5 – Log Out (exits/ends the program)
After a transaction is completed, the program will update the running balance and give the customer a detailed description of the transaction. A customer cannot overdraft on their account; if they try to withdraw more money than there is, a warning will be given to the customer. Also note that the ATM doesn’t distribute or collect coins – all monetary values are in whole dollars (e.g. an integer is an acceptable variable type). Any incorrect transaction types will display an appropriate message and count as a transaction.
C++ CODE FOR ATM WITH OUTPUT ATTACHED :
#include<bits/stdc++.h>
using namespace std;
//Main Function
int main(){
//Declaring and Initialising all necessary information Given
string name= "Robert";
string username= "BrownBrown";
string password= "blue123";
int savings=2500;
int checking=35;
while(1){
//Taking Operation Input From User About Operation
cout<<" 1 Deposit \n 2 Withdrawal \n 3 Balance Inquiry \n 4 Transfer Balance \n 5 Log Out"<<endl;
cout<<"Enter Choice : ";
int operation;
cin>>operation;
if(operation==1){
cout<<"Enter Amount(Whole Dollar) to Deposit"<<endl;
float amount;
int flag=0;
//checking if Amount enetered is Integer or not.
while(1){
cin>>amount;
int res=amount/1;
if(amount>0 and res*1==amount){
flag=1;
break;
}
else {
cout<<"Enter Whole Dollar, Bank Do not Collect Coins."<<endl;
}
}
//If Integer Amount Entered updating amount.
if(flag==1)savings+=(int)amount;
}
else if(operation==2){
cout<<"Enter Amount(Whole Dollar) to Withdraw"<<endl;
float amount;
int flag;
//checking Amount enetered is Integer or not.
while(1){
flag=0;
cin>>amount;
int res=amount/1;
if(amount>0 and res*1==amount){
flag=1;
}
else {
cout<<"Enter Whole Dollar, Bank Do not Distribute Coins."<<endl;
}
//checking if amount entered is available in account or not
if(flag==1){
if(amount<=savings){
flag=2;
break;
}
else {
cout<<"Not Sufficient Amount on Your Savings Account."<<endl;
break;
}
}
}
//If amount entered is available and is Integer updating amount in account
if(flag==2)savings-=(int)amount;
}
else if(operation==3){
cout<<"Savings Acoount"<<" $"<<savings<<endl;
cout<<"Checking Account"<<" $"<<checking<<endl;
}
else if(operation==4){
cout<<"Enter Amount to Transfer";
float transfer;
int flag;
//checking if Integer
while(1){
flag=0;
cin>>transfer;
int res=transfer/1;
if(transfer>0 and res*1==transfer){
flag=1;
}
else {
cout<<"Enter Whole Dollar, Bank Do not Operate on Coins."<<endl;
continue;
}
//If amount is available in account
if(flag==1){
if(transfer<=savings){
flag=2;
break;
}
else{
cout<<"Not Sufficient Balance In Savings Account."<<endl;
continue;
}
}
}
//If Amount is present in account, upating the transaction.
if(flag==2){
cout<<"Enter Account Number : "<<endl;
int accountno;
cin>>accountno;
savings-=(int)transfer;
}
}
else if(operation==5){
break;
}
else{
cout<<"Invalid Input"<<endl;
}
}
//Displaing Account after Transaction.
cout<<"Transaction Succesfull !"<<endl;
cout<<"Savings Account Balance : "<<savings<<endl;
cout<<"Checking Account : "<<checking<<endl;
}