-
Notifications
You must be signed in to change notification settings - Fork 0
/
atm.cpp
186 lines (167 loc) Β· 5.69 KB
/
atm.cpp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include <iostream>
#include <string>
class BankAccount {
public:
std::string name;
std::string userName;
std::string password;
std::string accountNo;
float balance = 0.0f;
int transactions = 0;
std::string transactionHistory = "";
bool login() {
std::cout << "Enter Your Username: ";
std::cin >> userName;
if (userName == this->userName) {
std::cout << "Enter Your Password: ";
std::cin >> password;
if (password == this->password) {
std::cout << "Login successful..." << std::endl;
return true;
} else {
std::cout << "Incorrect Password!!\nPlease Enter Correct Password and Try Again" << std::endl;
}
} else {
std::cout << "Username not found!!" << std::endl;
}
return false;
}
void withdraw() {
std::cout << "Enter amount to withdraw: ";
float amount;
std::cin >> amount;
if (amount <= 0) {
std::cout << "Invalid amount entered." << std::endl;
return;
}
if (balance >= amount) {
transactions++;
balance -= amount;
std::cout << "\nWithdraw Successful...." << std::endl;
std::string str = std::to_string(amount) + " Rs Withdrawn\n";
transactionHistory += str;
} else {
std::cout << "\nInsufficient Balance" << std::endl;
}
}
void registerUser() {
std::cout << "\nEnter Your Name: ";
std::cin.ignore();
std::getline(std::cin, name);
std::cout << "Enter Your Username: ";
std::cin >> userName;
std::cout << "Enter Your Password: ";
std::cin >> password;
std::cout << "Enter Your Account Number: ";
std::cin >> accountNo;
std::cout << "\nRegistration completed. Kindly login" << std::endl;
}
void transfer() {
std::cout << "\nEnter Recipient's Name: ";
std::string recipient;
std::cin.ignore();
std::getline(std::cin, recipient);
std::cout << "Enter amount to transfer: ";
float amount;
std::cin >> amount;
if (amount <= 0) {
std::cout << "Invalid amount entered." << std::endl;
return;
}
if (balance >= amount) {
if (amount <= 80000.0f) {
transactions++;
balance -= amount;
std::cout << "\nSuccessfully Transferred to " << recipient << std::endl;
std::string str = std::to_string(amount) + " Rs transferred to " + recipient + "\n";
transactionHistory += str;
} else {
std::cout << "\nSorry...Limit is 80000.00" << std::endl;
}
} else {
std::cout << "\nInsufficient Balance" << std::endl;
}
}
void checkBalance() {
std::cout << "\nBalance: " << balance << " Rs" << std::endl;
}
void displayTransactionHistory() {
if (transactions == 0) {
std::cout << "\nEmpty" << std::endl;
} else {
std::cout << "\nTransaction History:\n" << transactionHistory << std::endl;
}
}
void deposit() {
std::cout << "\nEnter amount to deposit: ";
float amount;
std::cin >> amount;
if (amount <= 0) {
std::cout << "Invalid amount entered." << std::endl;
return;
}
if (amount <= 200000.0f) {
transactions++;
balance += amount;
std::cout << "\nSuccessfully Deposited..." << std::endl;
std::string str = std::to_string(amount) + " Rs deposited\n";
transactionHistory += str;
} else {
std::cout << "\nSorry...Limit is 200000.00" << std::endl;
}
}
};
int main() {
std::cout << "\nWELCOME TO ATM SYSTEM\n";
std::cout << "1. Register\n";
std::cout << "2. Quit\n";
std::cout << "Enter Your Choice: ";
int choice;
std::cin >> choice;
if (choice == 1) {
BankAccount b;
b.registerUser();
while (true) {
std::cout << "\n1. Login\n2. Quit\n";
std::cout << "Enter Your Choice: ";
int n;
std::cin >> n;
if (n == 1) {
if (b.login()) {
std::cout << "\n\nWELCOME BACK " << b.name << "\n";
bool isFinished = false;
while (!isFinished) {
std::cout << "\n1. Withdraw\n2. Deposit\n3. Transfer\n4. Check Balance\n5. Transaction History\n6. Exit\n";
std::cout << "Enter Your Choice: ";
int c;
std::cin >> c;
switch (c) {
case 1:
b.withdraw();
break;
case 2:
b.deposit();
break;
case 3:
b.transfer();
break;
case 4:
b.checkBalance();
break;
case 5:
b.displayTransactionHistory(); // Corrected function name
break;
case 6:
isFinished = true;
break;
}
}
}
} else {
return 0;
}
}
} else {
return 0;
}
}