Answered step by step
Verified Expert Solution
Link Copied!

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 MAX_USERS 3// Constant for the maximum number of users
struct User // Structure for users info
{
int id;
char name[50];
string password;
double balance;
string transactionHistory;
};
// Function prototypes for operations in the ATM system
void displayMenu(User acc[], int userId);
void login(User acc[]);
void withdraw(User &acc);
void transfer(User &acc, User accList[], int userCount);
void checkBalance(User &acc);
void generateSlip(User &acc);
void quit();
int main()
{
User acc[3]; // Array For User accounts
// Open the file and read user data
ifstream read;
read.open("acc.txt");
if (!read)
{
cout << "Error opening file!" << endl;
}
// Read user data from the file
for (int i =0; i <3; i++)
{
read >> acc[i].id;
read.ignore();
read.getline(acc[i].name, 50);
read >> acc[i].password;
read >> acc[i].balance;
read.ignore();
getline(read, acc[i].transactionHistory);
}
// Close the file
read.close();
// Start the login process
login(acc);
}
// Function to handle user login
void login(User 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 =0; i <3; i++)
{
if (acc[i].id == id && acc[i].password == password)
{
loggedIn = true;
userId = i;
break;
}
}
if (!loggedIn)
{
cout << "Invalid ID or password. Please try again." << endl;
}
}
// Display the main menu after successful login
displayMenu(acc, userId);
}
// Function to display the main menu
void displayMenu(User 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, "<< acc[userId].name <<"!"<< endl;
cout <<"1. Withdraw" << endl;
cout <<"2. Transfer" << endl;
cout <<"3. Check Balance" << endl;
cout <<"4. Generate Slip" << endl;
cout <<"5. Quit" << endl;
cout <<"----------------------------------------------"<< endl;
cout << "Enter your option: ";
cin >> option;
switch (option){
case 1:
withdraw(acc[userId]);
break;
case 2:
transfer(acc[userId], acc, MAX_USERS);
break;
case 3:
checkBalance(acc[userId]);
break;
case 4:
generateSlip(acc[userId]);
break;
case 5:
quit();
default:
cout << "Invalid option. Please try again." << endl;
}
} while (option !=5);
}
// Function to handle money withdrawal
void withdraw(User &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: "+ to_string(amount)+"
";
cout << "Withdrawal successful. New balance: "<< acc.balance << endl;
}
}
// Function to handle money transfer
void transfer(User &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 =0; i < userCount; i++){
if (accList[i].id == targetId){
fou

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

Did you include SEC required financial data?

Answered: 1 week ago