Answered step by step
Verified Expert Solution
Question
1 Approved Answer
using the C + + code #include #include #include using namespace std; #define MAX _ USERS 3 / / Constant for the maximum number of
using the C code #include
#include
#include
using namespace std;
#define MAXUSERS Constant for the maximum number of users
struct User Structure for users info
int id;
char name;
string password;
double balance;
string transactionHistory;
;
Function prototypes for operations in the ATM system
void displayMenuUser acc int userId;
void loginUser acc;
void withdrawUser &acc;
void transferUser &acc, User accList int userCount;
void checkBalanceUser &acc;
void generateSlipUser &acc;
void quit;
int main
User acc; Array For User accounts
Open the file and read user data
ifstream read;
read.openacctxt;
if read
cout "Error opening file!" endl;
Read user data from the file
for int i ; i ; i
read acciid;
read.ignore;
read.getlineacciname, ;
read accipassword;
read accibalance;
read.ignore;
getlineread accitransactionHistory;
Close the file
read.close;
Start the login process
loginacc;
Function to handle user login
void loginUser acc
int id;
string password;
bool loggedIn false;
int userId;
Loop until the user successfully logs in
while loggedIn
cout "Enter your ID: ;
cin id; Read user ID
cout "Enter your password: ;
cin password; Read user password
for int i ; i ; i
if acciid id && accipassword password
loggedIn true;
userId i;
break;
if loggedIn
cout "Invalid ID or password. Please try again." endl;
Display the main menu after successful login
displayMenuacc userId;
Function to display the main menu
void displayMenuUser acc int userId
int option; Variable to store the user's menu selection
do
Display menu options
cout endl;
cout "Welcome to MAYBANK ATM BANKING SYSTEM, accuserIdname endl;
cout Withdraw" endl;
cout Transfer" endl;
cout Check Balance" endl;
cout Generate Slip" endl;
cout Quit" endl;
cout endl;
cout "Enter your option: ;
cin option;
switch option
case :
withdrawaccuserId;
break;
case :
transferaccuserId acc, MAXUSERS;
break;
case :
checkBalanceaccuserId;
break;
case :
generateSlipaccuserId;
break;
case :
quit;
default:
cout "Invalid option. Please try again." endl;
while option ;
Function to handle money withdrawal
void withdrawUser &acc
double amount;
cout "Enter amount to withdraw: ;
cin amount;
if amount acc.balance
cout "Insufficient balance." endl;
else
acc.balance amount;
acc.transactionHistory "Withdraw: tostringamount
;
cout "Withdrawal successful. New balance: acc.balance endl;
Function to handle money transfer
void transferUser &acc, User accList int userCount
int targetId;
double amount;
cout "Enter the ID of the account to transfer to: ;
cin targetId;
cout "Enter amount to transfer: ;
cin amount;
if amount acc.balance
cout "Insufficient balance." endl;
else
bool found false;
for int i ; i userCount; i
if accListiid targetId
fou
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started