In: Computer Science
writing a program that will act like an ATM machine by the end of this course. In order to access the ATM, the customer must enter their user name and their passcode. After 3 incorrect attempts at entering the user name and password, the program will end. The list of legitimate users along with their user ID, passcode and account balance will be provided to you.
There are only 5 functions that can be carried out by 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)
Allow the user to make up to a maximum of 3 transactions at a time. After 3 transactions, the program will terminate. Each transaction cannot exceed $500; for example, a user cannot withdraw more than $500.00, if there is $500.00 available on their account. 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.
The sample program is self explanatory, and with all the functions being listed as shown above.
And the sample program can be extended to allow three chances for authentication, and for all with addition of a simple for loop.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
class custaccount
{
public:
string name;
long passcode;
double accountno;
custaccount()
{
cout<<"Enter number:";
cin>>name;
cout<<"Enter Passcode:";
cin>>passcode;
cout<<"Enter accountno;";
cin>>accountno;
}
bool authenticate(string custname,int pass_code)
{
string custname;
long passcode;
int i=0;
cout<<"Enter Name:";
cin>>custname;
for(i=0;i<=20;i++)
{
cout<<"Enter passcode:";
cin>>pass_code;
int flag=0,j=0;
for(j-0;j<=20;j++)
{
if(pass_code==passcode)
{
flag=1;
}
else
{
flag-=0;
}
}
if(flag==1)
{
int i=0,j=0;
for(j=0;j<=20;j++)
{
if (cust_name=name[i])
{
flag1=1;
exit(0);
}
else
{
flag1==0;
exit(0);
}
}
flag1=0;
}
else
{
flag1==0;
}
return flag1;
}
}
};
void deposit(long amt,long accountno,string custname)
{
accontq1=accountno;
custnam=custname;
if(authenticate(accontq1,custname))
{
long depositsum;
cout<<"Enter amount you want to
deposit:";cin>>depositsum;
accountsum+=depositsum;
return 0;
}
void withdrawl(long amt, long accountno, string custname)
{
accontq1=accountno;
custnam=custname;
If(authenticate(account1,custnam))
{ long withdrawlsum;
cout<<"Enter amount you want to
deposit:";cin>>withdrawlsum;
accountsum-=withdrawlsum;
}
else
{
Return 0;
}
}
void balanceenquiry(long accountno)
{
custaccount a1;
int flag=0;
int I;
for(i=0;i<=20;i++)
{
if a1[i].account_no==accountno)
{
cout<<"Balance=";<<a[i].accountsum;
flag=1;
}
else
{
flag=0;
}
}
if(flag==0)
{
cout<<"account invalid:";
}
}
}
}
void transferbalance(long sendac, long recac, double accsum)
{
custaccount a1;
a1[sendac].accountsum-accsum;
a1[reccac].accountsum+=accsum;
return 0;
}
int main()
{
int accountno, passcode;
Cout<<"Enter accountno"; cin>>accountno;
cout<<"Enter passcode"; cin>>passcode;
If(authenticate(accountno,passcode)
{ int choice;
cout<<"Enter your choice 1. Withdrawl 2. Deposit 3. Balance
enquiry 4. Long out:"; cin>> choice;
switch(choice)
{
case'1': custaccount[accountno].withdrawl(amt);
break();
case'2': custaccount[accountno].deposit(amt);
break();
case'3':custaccount[accountno].balanceenquiry(accountno);
break();
case'4': cout<<"You are logged out:";exit(0);
}
}
else
{
cout<<"Invalid AccountNo."; exit(0);
}
return 0;
}