-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathntt.cpp
More file actions
595 lines (490 loc) · 13.5 KB
/
ntt.cpp
File metadata and controls
595 lines (490 loc) · 13.5 KB
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
//Continue testing and return all the function calls into main function, and bring the clear screen function and stabilixe it where possible.
#include<bits/stdc++.h>
#include<cstdlib>
#include<filesystem>
#include<string>
#include<stdexcept>
using namespace std;
set<string> months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
void universal_file(string fname, string accountnum, string password);
void deposit(string accountnum);
void registration();
string acc_correction(int num);
bool u_check(string name);
bool acc_num_check(string acc_num);
void options(string);
void intro();
string date_time();
void transfer(string);
void transfer_update_history(string, string, int, int, int);
void login();
void withdraw(string);
void operation_check();
void withdrawal_update_history(string, int, int);
void deposit_update_history(string a_number, int amount, int bal);
int main(){
intro();
return 0;
}
string date_time(){
auto now = chrono::system_clock::now();
time_t currentTime = chrono::system_clock::to_time_t(now);
tm localTime{};
#ifdef _WIN32
localtime_s(&localTime, ¤tTime);
#else
localtime_r(¤tTime, &localTime);
#endif
ostringstream oss;
oss << put_time(&localTime, "%Y-%m-%d %H:%M:%S");
return oss.str();
}
string acc_correction(int num){
string s = to_string(num);
while (s.length() < 10) {
s = "0" + s;
}
return s;
}
void add_universal_file(string fname, string accountnum, string password){
fstream myfile;
string bankname = "Major_";
string ext = ".txt";
//string temp = fname;
//bankname.appenD(fname);
bankname.append(fname);
bankname.append(ext);
myfile.open(bankname, ios::out);
myfile << accountnum << endl;
myfile << password << endl;
myfile.close();
}
void intro(){
cout << "Hello, How's your day?\n";
//cout << "What operation do you want to do today?\n";
cout << "\t1. Login.\n\t2. Register.\n";
int ans;
cin >> ans;
if(ans == 1){
login();
}else if(ans == 2){
registration();
}
if(ans != 1 || ans != 2){
intro();
}
}
string universal_extract(string name){
fstream myfile;
string ext = "Major_";
string ext2 = ".txt";
ext.append(name);
ext.append(ext2);
myfile.open(ext);
string line;
//int linenum;
getline(myfile, line);
myfile.close();
return line;
}
bool u_check(string name){
fstream my_file;
string bankname = "Major_";
string ext = ".txt";
bankname.append(name);
bankname.append(ext);
//string filename = bankname;
my_file.open(bankname, ios::in);
if(!my_file.is_open()){
return false;
}else{
my_file.close();
return true;
}
// string line;
// int linenum = 0;
// while(getline(my_file, line)){
// linenum++;
// }
// my_file.close();
// if(linenum <= 1){
// filesystem::remove(bankname);
// return false;
// }else{
// return true;
// }
}
bool acc_num_check(string acc_num){
fstream myfile;
string ext = "_info.txt";
string bankname = "Dbank_";
//bool check = false;
bankname.append(acc_num);
bankname.append(ext);
string filename = bankname;
string line;
int linenum = 0;
myfile.open(bankname, ios::in);
getline(myfile, line);
myfile.close();
if(line.size() == 0){
filesystem::remove(filename);
return false;
}else{
return true;
}
}
void operation_check(){
cout << "Do you want to perform another transaction?\n\t1. Yes\n\t2. No\n";
int ans;
while(cin >> ans){
if(ans == 1){
login();
}
if(ans == 2){
cout << "Bye-bye.\n";
cout << "..............................................................................\n";
exit(0);
}
cout << "Invalid opotion.\n";
}
}
void login(){
fstream myfile;
string username;
string password;
string temp;
string ext = "Major_";
string ext2 = ".txt";
//uc:
cout << "Enter your username: ";
cin >> username;
cout << "Enter your password: ";
cin >> password;
bool lc = u_check(username);
while(lc == false){
cout << "Invalid login details. Try again.\n";
login();
}
temp = username;
ext.append(temp);
ext.append(ext2);
myfile.open(temp, ios::out);
int linenum = 0;
string line;
while(getline(myfile, line)){
linenum++;
if(linenum == 2 && line != password){
cout << "Invalid Password.\n";
for(int i = 0; i < 3; i++){
cout << "\t...............................\n";
}
myfile.close();
intro();
}
}
myfile.close();
options(username);
}
void options(string name){
cout << "\tACCESS GRANTED ^_^\n\n";
string acc_num = universal_extract(name);
int ans;
cout << "\t1. Withdraw\n\t2. Transfer\n\t3. Deposit\n\t4. Exit\n";
cin >> ans;
if(ans == 1){
withdraw(acc_num);
}else if(ans == 2){
transfer(acc_num);
}else if(ans == 3){
deposit(acc_num);
}else if(ans == 4){
cout << "Bye-bye\n";
cout << "..............................................................................\n";
exit(0);
}else{
operation_check();
}
}
void withdraw(string a_num){
fstream myfile;
string ext = "Dbank_";
string ext2 = "_balance.txt";
string temp = a_num;
ext.append(a_num);
ext.append(ext2);
myfile.open(ext, ios::in);
int line;
string balance;
getline(myfile, balance);
myfile.close();
try{
line = stoi(balance);
}catch(...){
line = 0;
}
cout << "How much do you want to withdraw?\n";
int ans;
cin >> ans;
if(line > ans){
line = line-ans;
myfile.open(ext, ios::out);
myfile << line << endl;
myfile.close();
withdrawal_update_history(temp, ans, line);
cout << "Withdrawal Successful.\n";
operation_check();
}else{
cout << "Insufficient balance.\n";
operation_check();
}
}
void withdrawal_update_history(string a_number, int amount, int bal){
fstream myfile;
string ext = "_history.txt";
string bankname = "Dbank_";
string dt = date_time();
bankname.append(a_number);
bankname.append(ext);
myfile.open(bankname, ios::app);
myfile << "History: Account was Debited." << endl;
myfile << "Amount = " << amount << endl;
myfile << "Date & Time: " << dt << endl;
myfile << "Balance: " << bal << endl;
myfile << ".........." << endl;
myfile.close();
}
void transfer(string s_name){
fstream myfile;
string ext = "_balance.txt";
string bankname = "Dbank_";
string ext2 = "_balance.txt";
string bankname2 = "Dbank_";
cout << "How much do you want to transfer?\n";
int amount;
cin >> amount;
cout << "Enter the reciever's account number;\n";
string r_a_n;
cin >> r_a_n;
//string send = to_string(r_a_n);
bool check_a_n = acc_num_check(r_a_n);
if(check_a_n == false){
cout << "Invalid reciever's detail.\n";
operation_check();
}
bankname.append(s_name);
bankname.append(ext);
string line;
int balance;
myfile.open(bankname, ios::in);
getline(myfile, line);
myfile.close();
try{
balance = stoi(line);
}catch(...){
balance = 0;
}
int temp_balance = balance;
if(balance < amount){
cout << "Insufficient balance.\n";
operation_check();
}
bankname2.append(r_a_n);
bankname2.append(ext2);
myfile.open(bankname2, ios::in);
getline(myfile, line);
myfile.close();
try{
balance = stoi(line);
}catch(...){
balance = 0;
}
balance = balance+amount;
myfile.open(bankname2, ios::out);
myfile << balance << endl;
myfile.close();
temp_balance = temp_balance-amount;
myfile.open(bankname, ios::out);
myfile << balance << endl;
myfile.close();
transfer_update_history(s_name, r_a_n, amount, temp_balance, balance);
operation_check();
}
void transfer_update_history(string s_a_n, string r_a_n, int amount, int s_balance, int r_balance){
fstream myfile;
string ext = "_history.txt";
string bankname = "Dbank_";
string temp = bankname;
string dt = date_time();
bankname.append(s_a_n);
bankname.append(ext);
myfile.open(bankname, ios::app);
myfile << "History: Account was Debited." << endl;
myfile << "Amount = " << amount << endl;
myfile << "Date & Time: " << dt << endl;
myfile << "Balance: " << s_balance << endl;
myfile << ".........." << endl;
myfile.close();
temp.append(r_a_n);
temp.append(ext);
myfile.open(temp, ios::app);
myfile << "History: Account was Credited." << endl;
myfile << "Amount = " << amount << endl;
myfile << "Date & Time: " << dt << endl;
myfile << "Balance: " << r_balance;
myfile << ".........." << endl;
myfile.close();
}
void deposit(string accountnum){
fstream myfile;
string ext1 = "Dbank_";
string ext2 = "_balance.txt";
string line;
int balance;
ext1.append(accountnum);
ext1.append(ext2);
myfile.open(ext1, ios::in);
getline(myfile, line);
myfile.close();
cout << line;
try{
balance = stoi(line);
}catch(...){
balance = 0;
}
cout << "How much do you want to deposit?\n";
int ans;
cin >> ans;
balance = balance+ans;
myfile.open(ext1, ios::out);
myfile << balance << endl;
myfile.close();
deposit_update_history(accountnum, ans, balance);
cout << "Deposit Successful ^_^\n";
intro();
}
void deposit_update_history(string a_number, int amount, int bal){
fstream myfile;
string ext = "_history.txt";
string bankname = "Dbank_";
string dt = date_time();
bankname.append(a_number);
bankname.append(ext);
myfile.open(bankname, ios::app);
myfile << "History: Account was Credited." << endl;
myfile << "Amount = " << amount << endl;
myfile << "Date & Time: " << dt << endl;
myfile << "Balance: " << bal << endl;
myfile << ".........." << endl;
myfile.close();
}
void registration(){
fstream myfile;
ac:
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> distrib_int(1, 100000000);
long long acc_num = distrib_int(gen);
string account_n = acc_correction(acc_num);
bool check = acc_num_check(account_n);
if(check == true){
goto ac;
}
string ext = ".txt";
string ext2 = "_balance.txt";
string ext3 = "_history.txt";
string ext4 = "_info.txt";
string bank_name = "Dbank_";
string bankname = "Dbank_";
string temp = account_n;
string name;
int dob_day;
string dob_month;
int dob_year;
string address;
long long phone_num;
string email;
string username;
string password;
string cp;
cout << "Enter your name: ";
cin.ignore();
getline(cin, name);
dc:
cout << "Enter the day you were born: ";
cin >> dob_day;
if(dob_day > 31 || dob_day < 1){
cout << "Invalid day!\n";
goto dc;
}
mc:
cout << "Enter the month you were born: ";
cin >> dob_month;
if(months.count(dob_month) != 1){
cout << "Invalid month. First letter is always capital.\n";
goto mc;
}
yc:
cout << "Enter the year you were born: ";
cin >> dob_year;
if(dob_year > 2025 || dob_year < 1900){
cout << "Invalid year.\n";
goto yc;
}
cout << "Enter your Home Address: ";
cin.ignore();
getline(cin, address);
cout << "Enter your Phone Number: ";
cin >> phone_num;
cout << "Enter your Email: ";
cin >> email;
cout << "Enter your username: ";
cin >> username;
while(username.size() <= 5){
cout << "Username can't be " << username.size() << " letters.\n";
//goto uc;
cout << "Enter your username: ";
cin >> username;
}
bool check_file = u_check(username);
while(check_file == true){
cout << "It has been taken.\n";
//goto uc;
cout << "Enter your username: ";
cin >> username;
check_file = u_check(username);
}
pt:
cout << "Enter your password: ";
cin >> password;
cout << "Confirm your Password: ";
cin >> cp;
if(cp != password){
cout << "Password does'nt match\n";
goto pt;
}
add_universal_file(username, account_n, password);
bank_name.append(temp);
bank_name.append(ext4);
myfile.open(bank_name, ios::out);
myfile << account_n << endl;
myfile << "Name: " << name << endl;
myfile << "DOB: " << dob_day << ", " << dob_month << ", " << dob_year << endl;
myfile << "Address: " << address << endl;
myfile << "Phone Number: " << phone_num << endl;
myfile << "Email: " << email << endl;
myfile << username << endl;
myfile << password << endl;
myfile.close();
cout << "\nYOUR ACCOUNT NUMBER IS: " << account_n << ".\n\t\t*Copy it down somewhere.\n";
cout << "\nDo you want to make a Deposit?\n\t1. Yes\n\t2.No\n";
int ans;
cin >> ans;
if(ans == 1){
deposit(account_n);
}else{
cout << "Bye-bye\n";
cout << "..............................................................................\n";
exit(0);
}
}