-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBank_Management.cpp
444 lines (422 loc) · 17.1 KB
/
Bank_Management.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <ctime>
#include <iomanip>
#include <algorithm>
#include <sstream>
using namespace std;
class Bank {
private:
string date;
string dob;
string email;
vector<string> transactionHistory;
public:
double balance;
int age;
string first_name;
string last_name;
long long acc_no;
void CreateBankAccount();
void UpdateBankAccount();
void DeleteBankAccount();
void SearchBankAccount();
//void ListAccounts();
void Transact();
void BankStatement();
};
void Bank::CreateBankAccount() {
balance = 0.0;
cout << "--------------------------------------------------------" << endl;
cout << " ENTER THE GIVEN DETAILS " << endl;
cout << "--------------------------------------------------------" << endl;
cout << "Enter your First Name : ";
cin >> first_name;
cout << "Enter your Last Name : ";
cin.ignore();
getline(cin, last_name);
cout << "Enter your D.O.B (in DD/MM/YYYY) : ";
cin >> dob;
cout << "Enter your age : ";
cin >> age;
cout << "Enter your Email ID : ";
cin >> email;
srand((unsigned)time(NULL));
acc_no = rand();
cout << "--------------------------------------------------------" << endl;
cout << " THE ACCOUNT NUMBER : " << acc_no << endl;
cout << endl;
cout << "Account " << acc_no << " has been successfully created." << endl;
cout << endl;
cout << "Press Enter to go to the Home Page ";
cin.ignore();
cin.get();
}
void Bank::UpdateBankAccount() {
int c1;
cout << "----------------------------------------------------" << endl;
cout << " UPDATION COUNTER " << endl;
cout << "----------------------------------------------------" << endl;
cout << " YOUR ACCOUNT NUMBER : " << acc_no << endl;
cout << endl;
cout << "What Updation do you need in " << acc_no << " ? \n";
cout << endl;
cout << "1) First Name " << endl;
cout << "2) Last Name " << endl;
cout << "3) D.O.B " << endl;
cout << "4) Age " << endl;
cout << "5) Email ID " << endl;
cout << "----------------------------------------------------" << endl;
cout << "Enter the Choice : ";
cin >> c1;
switch (c1) {
case 1: {
string fs;
string copyfs = first_name;
cout << "Enter the Updated First Name : ";
cin >> fs;
first_name = fs;
cout << "----------------------------------------------------" << endl;
cout << " The Updation is successful from " << copyfs << " ---> " << first_name << endl;
break;
}
case 2: {
string ls;
string copyls = last_name;
cout << "Enter the Updated Last Name : ";
cin >> ls;
last_name = ls;
cout << "----------------------------------------------------" << endl;
cout << " The Updation is successful from " << copyls << " ---> " << last_name << endl;
break;
}
case 3: {
string dob1;
string copydob1 = dob;
cout << "Enter the Updated D.O.B : ";
cin >> dob1;
dob = dob1;
cout << "----------------------------------------------------" << endl;
cout << " The Updation is successful from " << copydob1 << " ---> " << dob << endl;
break;
}
case 4: {
int age1;
int copyage = age;
cout << "Enter the Updated Age : ";
cin >> age1;
age = age1;
cout << "----------------------------------------------------" << endl;
cout << " The Updation is successful from " << copyage << " ---> " << age << endl;
break;
}
case 5: {
string email_1;
string copyem = email;
cout << "Enter the Updated Email : ";
cin >> email_1;
email = email_1;
cout << "----------------------------------------------------" << endl;
cout << " The Updation is successful from " << copyem << " ---> " << email << endl;
break;
}
default:
cout << "Enter Valid Options" << endl;
}
cout << endl;
cout << endl;
cout << "Press Enter to go to the Home Page ";
cin.ignore();
cin.get();
}
/*
void Bank::ListAccounts() {
cout << "---------------------------------------------------------------" << endl;
cout << " BANK ACCOUNTS " << endl;
cout << "---------------------------------------------------------------" << endl;
cout << " Account Number | Name | Age | Balance " << endl;
cout << "---------------------------------------------------------------" << endl;
cout << acc_no << " | " << (first_name + " " + last_name) << "| " << age << " | Rs. " << fixed << setprecision(2) << balance << endl;
cout << "---------------------------------------------------------------" << endl;
cout << endl;
cout << "Press Enter to go to the Home Page ";
cin.ignore();
cin.get();
}*/
void Bank::Transact() {
string choice;
double amt;
cout << "---------------------------------------------------------------" << endl;
cout << " BANK NAME " << endl;
cout << "---------------------------------------------------------------" << endl;
cout << "ACC NO : " << acc_no << endl;
cout << endl;
cout << " ------------------------------ " << endl;
cout << " | | " << endl;
cout << " | DEPOSIT | " << endl;
cout << " | | " << endl;
cout << " ------------------------------ " << endl;
cout << " ------------------------------ " << endl;
cout << " | | " << endl;
cout << " | WITHDRAW | " << endl;
cout << " | | " << endl;
cout << " ------------------------------ " << endl;
cout << "---------------------------------------------------------------" << endl;
cout << "Enter the action : ";
cin >> choice;
transform(choice.begin(), choice.end(), choice.begin(), ::tolower);
if (choice == "deposit") {
cout << "Enter the amount to be deposited : Rs.";
cin >> amt;
balance += amt;
ostringstream oss;
oss << fixed << setprecision(2) << amt;
string transaction = "Credited Rs. " + oss.str();
transactionHistory.push_back(transaction);
cout << endl;
cout << "Amount Rs." << amt << " has been credited to your acc " << acc_no << "." << endl;
cout << endl;
cout << "---------------------------------------------------------------" << endl;
cout << " Current Balance : Rs." << balance << endl;
} else if (choice == "withdraw") {
cout << "Enter the amount to be withdrawn : Rs.";
cin >> amt;
if (amt > balance) {
cout << "Insufficient balance." << endl;
} else {
balance -= amt;
ostringstream oss;
oss << fixed << setprecision(2) << amt;
string transaction = "Debited Rs. " + oss.str();
transactionHistory.push_back(transaction);
cout << endl;
cout << "Amount Rs." << amt << " has been debited from your acc " << acc_no << "." << endl;
cout << endl;
cout << "---------------------------------------------------------------" << endl;
cout << " Current Balance : Rs." << balance << endl;
}
} else {
cout << "Please check the spelling or enter the required field alone." << endl;
}
cout << endl;
cout << endl;
cout << "Press Enter to go to the Home Page ";
cin.ignore();
cin.get();
}
void Bank::BankStatement() {
cout << "---------------------------------------------------------------" << endl;
cout << " BANK STATEMENT " << endl;
cout << "---------------------------------------------------------------" << endl;
cout << " Date & Time | Transaction Description " << endl;
cout << "---------------------------------------------------------------" << endl;
for (size_t i = 0; i < transactionHistory.size(); ++i) {
time_t now = time(0);
tm* ltm = localtime(&now);
char dt[20];
strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", ltm);
cout << setw(27) << dt << " | " << transactionHistory[i] << endl;
}
cout << "---------------------------------------------------------------" << endl;
cout << endl;
cout << "Press Enter to go to the Home Page ";
cin.ignore();
cin.get();
}
void Bank::DeleteBankAccount() {
string yn;
cout << "---------------------------------------------------------------" << endl;
cout << " BANK NAME " << endl;
cout << "---------------------------------------------------------------" << endl;
cout << endl;
cout << " Are you sure that you want to delete your Bank Account Details" << endl;
cout << " (YES/NO) " << endl;
cout << endl;
cout << " Enter your choice : ";
cin >> yn;
transform(yn.begin(), yn.end(), yn.begin(), ::tolower);
cout << endl;
if (yn == "y" || yn == "yes") {
cout << " Account " << acc_no << " has been deleted." << endl;
first_name = "";
last_name = "";
dob = "";
age = 0;
email = "";
balance = 0.0;
acc_no = 0;
transactionHistory.clear();
} else {
cout << " Account Deletion Cancelled. " << endl;
}
cout << endl;
cout << endl;
cout << "Press Enter to go to the Home Page ";
cin.ignore();
cin.get();
}
int main() {
int c;
vector<Bank> accounts; // Store multiple user accounts
while (1) {
cout << "----------------------------------------" << endl;
cout << " BANK NAME " << endl;
cout << "----------------------------------------" << endl;
cout << endl;
cout << "1) Create Account\n";
cout << "2) Update Account\n";
cout << "3) Delete Account\n";
cout << "4) List Accounts\n";
cout << "5) Transact (Withdraw/Deposit) \n";
cout << "6) Bank Statement\n";
cout << "7) Exit\n";
cout << "----------------------------------------" << endl;
cout << "ENTER YOUR CHOICE: ";
cin >> c;
switch (c) {
case 1: {
system("cls");
Bank newAccount;
newAccount.CreateBankAccount();
accounts.push_back(newAccount);
system("cls");
break;
}
case 2: {
system("cls");
cout << "----------------------------------------------------" << endl;
for(int i=0;i<accounts.size();i++){
cout << "Account Number : " << accounts[i].acc_no << endl;
cout << "Account Holder : " << accounts[i].first_name << " " << accounts[i].last_name << endl;
cout << "----------------------------------------------------" << endl;
}
cout << endl;
int accNo;
cout << "Enter the Account Number to Update: ";
cin >> accNo;
bool found = false;
for (int i = 0; i < accounts.size(); ++i) {
if (accounts[i].acc_no == accNo) {
accounts[i].UpdateBankAccount();
found = true;
break;
}
}
if (!found) {
cout << "Account not found." << endl;
}
system("cls");
break;
}
case 3: {
system("cls");
cout << "---------------------------------------------------------------" << endl;
for(int i=0;i<accounts.size();i++){
cout << "Account Number : " << accounts[i].acc_no << endl;
cout << "Account Holder : " << accounts[i].first_name << " " << accounts[i].last_name << endl;
cout << "---------------------------------------------------------------" << endl;
}
cout << endl;
int accNo;
cout << "Enter the Account Number to Delete: ";
cin >> accNo;
for (int i = 0; i < accounts.size(); ++i) {
if (accounts[i].acc_no == accNo) {
accounts[i].DeleteBankAccount();
accounts.erase(accounts.begin() + i);
break;
}
}
system("cls");
break;
}
case 4: {
system("cls");
if (accounts.empty()) {
cout << "No accounts found." << endl;
}
else {
cout << "---------------------------------------------------------------" << endl;
cout << " ACCOUNTS " << endl;
cout << "---------------------------------------------------------------" << endl;
for (int i = 0; i < accounts.size(); ++i) {
cout << "Account " << i + 1 << endl;
cout << " Account Number : " << accounts[i].acc_no << endl;
cout << " Name : " << accounts[i].first_name << " " << accounts[i].last_name << endl;
cout << " Age : " << accounts[i].age << endl;
cout << " Balance : Rs. " << fixed << setprecision(2) << accounts[i].balance << endl;
cout << "---------------------------------------------------------------" << endl;
}
cout << endl;
cout << "Press Enter to return to the Home Page ";
cin.ignore();
cin.get();
}
system("cls");
break;
}
case 5: {
system("cls");
cout << "---------------------------------------------------------------" << endl;
for(int i=0;i<accounts.size();i++){
cout << "Account Number : " << accounts[i].acc_no << endl;
cout << "Account Holder : " << accounts[i].first_name << " " << accounts[i].last_name << endl;
cout << "---------------------------------------------------------------" << endl;
}
cout << endl;
int accNo;
cout << "Enter the Account Number to Transact: ";
cin >> accNo;
bool found = false;
for (int i = 0; i < accounts.size(); ++i) {
if (accounts[i].acc_no == accNo) {
accounts[i].Transact();
found = true;
break;
}
}
if (!found) {
cout << "Account not found." << endl;
}
system("cls");
break;
}
case 6: {
system("cls");
cout << "---------------------------------------------------------------" << endl;
for(int i=0;i<accounts.size();i++){
cout << "Account Number : " << accounts[i].acc_no << endl;
cout << "Account Holder : " << accounts[i].first_name << " " << accounts[i].last_name << endl;
cout << "---------------------------------------------------------------" << endl;
}
cout << endl;
int accNo;
cout << "Enter the Account Number for Bank Statement: ";
cin >> accNo;
bool found = false;
for (int i = 0; i < accounts.size(); ++i) {
if (accounts[i].acc_no == accNo) {
accounts[i].BankStatement();
found = true;
break;
}
}
if (!found) {
cout << "Account not found." << endl;
}
system("cls");
break;
}
case 7: {
cout << "Exiting the program..." << endl;
return 0;
}
default:
cout << "Invalid choice." << endl;
cout << endl;
}
}
return 0;
}