-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitignore
138 lines (111 loc) · 3.45 KB
/
.gitignore
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// project ATM MACHINE in c++ //
#include<iostream>
#include<vector>
#include<string>
using namespace std;
// Sample Account class
class Account {
private:
string accountNumber;
string pin;
double balance;
public:
Account(string accNumber, string pin, double balance) : accountNumber(accNumber), pin(pin), balance(balance) {}
string getAccountNumber() const {
return accountNumber;
}
string getPin() const {
return pin;
}
double getBalance() const {
return balance;
}
void deposit(double amount) {
balance += amount;
}
bool withdraw(double amount) {
if (amount > 0 && balance >= amount) {
balance -= amount;
return true;
}
return false;
}
};
// Sample ATM class
class ATM {
private:
vector<Account> accounts;
Account* currentAccount;
public:
ATM() {
// Sample accounts
accounts.push_back(Account("123456", "1234", 1000.0));
accounts.push_back(Account("789012", "5678", 500.0));
currentAccount = nullptr;
}
bool authenticate(string accountNumber, string pin) {
for (auto& acc : accounts) {
if (acc.getAccountNumber() == accountNumber && acc.getPin() == pin) {
currentAccount = &acc;
return true;
}
}
return false;
}
void displayMenu() {
cout << "1. Check Balance" << endl;
cout << "2. Deposit" << endl;
cout << "3. Withdraw" << endl;
cout << "4. Logout" << endl;
}
void run() {
string accountNumber, pin;
cout << "Enter Account Number: ";
cin >> accountNumber;
cout << "Enter PIN: ";
cin >> pin;
if (authenticate(accountNumber, pin)) {
int choice;
do {
displayMenu();
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "Balance: $" << currentAccount->getBalance() << endl;
break;
case 2:
double depositAmount;
cout << "Enter deposit amount: $";
cin >> depositAmount;
currentAccount->deposit(depositAmount);
cout << "Deposit successful. New balance: $" << currentAccount->getBalance() << endl;
break;
case 3:
double withdrawAmount;
cout << "Enter withdraw amount: $";
cin >> withdrawAmount;
if (currentAccount->withdraw(withdrawAmount)) {
cout << "Withdrawal successful. New balance: $" << currentAccount->getBalance() << endl;
} else {
cout << "Insufficient funds or invalid amount." << endl;
}
break;
case 4:
cout << "Logging out..." << endl;
break;
default:
cout << "Invalid choice. Try again." << endl;
}
} while (choice != 4);
} else {
cout << "Authentication failed. Invalid account number or PIN." << endl;
}
}
};
int main()
{
ATM atm;
atm.run();
return 0;
}