-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.cpp
More file actions
1409 lines (1376 loc) · 52.5 KB
/
project.cpp
File metadata and controls
1409 lines (1376 loc) · 52.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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include<iostream>
#include<string>
#include<string.h>
#include<fstream>
#include<time.h>
#include<ctime>
#include<windows.h>
#include<conio.h>
#include<limits>
#include<dos.h>
#include<iomanip>
#include<algorithm>
//#include<chrono>
using namespace std;
//using namespace std::chrono;
int hdrscr();
class bank{
protected:
string first_name,last_name,father_firstname,mother_firstname,grandfather_firstname,father_lastname,mother_lastname,grandfather_lastname,username,password;
string province,district,municipality,tole,email,mob_num,bank_accnum;
char gender;
int year,month,day,ward,acc_no,acc_type;
float bank_balance;
public:
void DOB(){
cin>>year>>month>>day;
//getting the current date
// system_clock::time_point now = system_clock::now();
// time_t now_c = system_clock::to_time_t(now);
// tm current_tm = *localtime(&now_c);
// int currentYear = current_tm.tm_year + 1900; // Gregorian year
time_t tim=time(0);
tm* atime=localtime(&tim);
int currentyear=atime->tm_year+1900+57;
// Calculate the age in BS
int age = (currentyear) - year ;
if(cin.fail()||(age<18)||(month>12||month<=0)||(day>31||day<=0)){ //cin.fail() is used to check if the input is of the correct type. If it returns true, it means that the input is not an integer.
cout<<"\n\t\t\t Invalid date";
cin.clear(); // Clear error state
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // Ignore invalid input
cout<<"\n\t\t\t Enter again\n\t\t";
cout<<"\n\t\tEnter Your Date of Birth(year/month/day) in B.S. : ";
DOB();
}
}
void phone_number() {
cout << "\n\t\t+977-";
cin.clear();
cin >> mob_num;
if (mob_num.length() != 10 || !isNumeric(mob_num)) {
cout << "\n\t\tInvalid mobile number.\n\t\tEnter again" ;
phone_number();
}
bool found = checkIfPhoneNumberExists(mob_num);
if (found) {
cout << "\n\t\tThis mobile number is already used." << endl;
cout << "\n\t\tEnter again: ";
phone_number();
}
}
bool isNumeric(const string &str) {
return all_of(str.begin(), str.end(), ::isdigit);
}
bool checkIfPhoneNumberExists(const string &phone_number) {
ifstream fin;
fin.open("useridpw.txt");
string line, mnum, p;
bool found = false;
while (getline(fin, line)) {
stringstream iss(line);
iss >> mnum >> p;
if (mnum == phone_number) {
found = true;
break;
}
}
fin.close();
return found;
}
void bank_accnumber(){
string bank_code="0112",random; // no_of_acc is no of account , acc_type is account type
string ran,a,b,c,d,e;
srand(time(0));// Seed the random number generator with current time
int randomNumber[5];
for(int i=0;i<5;i++){
randomNumber[i] = rand()%10;
}
a=to_string(randomNumber[0]);
b=to_string(randomNumber[1]);
c=to_string(randomNumber[2]);
d=to_string(randomNumber[3]);
e=to_string(randomNumber[4]);
random=a+b+c+d+e;
//cout<<random<<endl;
string account_type;
account_type=to_string(acc_type);
bank_accnum=bank_code+random+account_type;
}
void bank_accbalance(){
bank_balance=0;
}
void search_display(){
cout<<"\n\t\t_____________________________________________________________________________________________\n";
cout<<"\t\t_____________________________________________________________________________________________\n";
cout<<"\t\t \n";
cout<<"\t\t \n";
cout<<"\t\t \n";
cout<<"\t\t Name::\t\t\t"<<first_name<<" "<<last_name<<endl;
cout<<"\t\t Account No::\t\t"<<bank_accnum<<endl;
cout<<"\t\t Bank Balance::\t\t"<<bank_balance<<endl;
cout<<"\t\t Grand Father name::\t"<<grandfather_firstname<<" "<<grandfather_lastname<<endl;
cout<<"\t\t Father name::\t\t"<<father_firstname<<" "<<father_lastname<<endl;
cout<<"\t\t Mother name::\t\t"<<mother_firstname<<" "<<mother_lastname<<endl;
cout<<"\t\t Date of birth::\t\t"<<year<<"/"<<month<<"/"<<day<<" \n";
cout<<"\t\t Mobile no::\t\t"<<mob_num<<" \n";
cout<<"\t\t Email::\t\t\t"<<email<<" \n";
cout<<"\t\t Province::\t\t"<<province<<" \n";
cout<<"\t\t District::\t\t"<<district<<" \n";
cout<<"\t\t Address::\t\t"<<municipality<<"-"<<ward<<","<<tole<<" \n";
cout<<"\t\t Gender::\t\t"<<gender<<" \n";
cout<<"\t\t_____________________________________________________________________________________________\n";
cout<<"\t\t_____________________________________________________________________________________________\n\n\n\n\t\t\t\t\t";
}
bool isValidGmail(const string &email) {
size_t position = email.find("@");
return (position != string::npos && email.substr(position + 1) == "gmail.com");
}
void us_email(){
// cin.ignore();
// cin.clear();
// cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
// getline(cin,email);
cin>>email;
size_t position;
position=email.find("@");
if (isValidGmail(email)) {
//valid email
}
else {
cout << "\n\t\tInvalid Email.\n\t\tEnter again\n\t\t";
us_email(); // Prompt again for email if it's invalid
}
}
};
class admin:public bank{
public:
void admin_login();
void admin_page();
void create_user();
void search_user();
void search_by_name(const string& name);
void search_by_acc_num(const string& number);
void tasks();
void deposit(const string &name,const string& accnum,double money);
void withdraw(const string& name, const string& accnum, double money);
void edit_acc();
void delete_acc(const string& name, const string& accnum);
void cpy();
};
class user:public admin{
string user_username,user_password;
string current_password,new_password;
public:
void user_login();
void user_page();
void user_information();
void password();
void change_password();
void transaction_history();
void user_display(const string& first_name,const string& last_name,const string& mob_num,float bank_balance,const string& bank_accnum,const string& grandfather_firstname,const string& grandfather_lastname,const string& father_firstname,const string& father_lastname,const string& mother_firstname,const string& mother_lastname,int year,int month,int day,const string& province,const string& district,const string& municipality,int ward,const string& tole,char gender,const string& email){
cout<<"\n\t\t_____________________________________________________________________________________________\n";
cout<<"\t\t_____________________________________________________________________________________________\n";
cout<<"\t\t \n";
cout<<"\t\t \n";
cout<<"\t\t \n";
cout<<"\t\t Name::\t\t\t"<<first_name<<" "<<last_name<<endl;
cout<<"\t\t Account No::\t\t"<<bank_accnum<<endl;
cout<<"\t\t Bank Balance::\t\t"<<bank_balance<<endl;
cout<<"\t\t Grand Father name::\t"<<grandfather_firstname<<" "<<grandfather_lastname<<endl;
cout<<"\t\t Father name::\t\t"<<father_firstname<<" "<<father_lastname<<endl;
cout<<"\t\t Mother name::\t\t"<<mother_firstname<<" "<<mother_lastname<<endl;
cout<<"\t\t Date of birth::\t\t"<<year<<"/"<<month<<"/"<<day<<" \n";
cout<<"\t\t Mobile no::\t\t"<<mob_num<<" \n";
cout<<"\t\t Email::\t\t\t"<<email<<" \n";
cout<<"\t\t Province::\t\t"<<province<<" \n";
cout<<"\t\t District::\t\t"<<district<<" \n";
cout<<"\t\t Address::\t\t"<<municipality<<" "<<ward<<","<<tole<<" \n";
cout<<"\t\t Gender::\t\t"<<gender<<" \n";
cout<<"\t\t_____________________________________________________________________________________________\n";
cout<<"\t\t_____________________________________________________________________________________________\n\n\n\n\t\t\t\t\t";
}
};
void login_page(){
system("cls");
hdrscr();
int choice;
here:
cout<<"\n\n\t\t"<<char(201);
for(int i=0;i<80;i++)
{
cout<<char(205);
}
cout<<char(187)<<endl;
for(int i=0;i<4;i++)
{
cout<<"\t\t"<<char(186)<<"\t\t\t\t\t\t\t\t\t\t "<<char(186)<<endl;
}
cout<<"\t\t"<<char(186)<<"\t\t\t Enter your login type: \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [1] Admin \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [2] User \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [3] Exit \t\t "<<char(186)<<endl;
for(int i=0;i<11;i++)
{
cout<<"\t\t"<<char(186)<<"\t\t\t\t\t\t\t\t\t\t "<<char(186)<<endl;
}
cout<<"\t\t"<<char(200);
for(int i=0;i<80;i++)
{
cout<<char(205);
}
cout<<char(188)<<endl<<endl;
choice=getch(); //data input
switch(choice)
{
case '1':{
system("cls");
admin ad_obj;
ad_obj.admin_login();
break;
}
case '2':{
system("cls");
user us_obj;
us_obj.user_login();
break;
}
case '3':{
exit(0);
}
default:
system("cls");
cout<<"\n\t\tInvalid choice! Try again\n";
system("pause");
system("cls");
goto here;
}
}
int hdrscr(){
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
cfi.nFont = 16;
cfi.dwFontSize.X = 10; // Width of each character in the font
cfi.dwFontSize.Y = 21.5; // Height
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_BOLD;
wcscpy(cfi.FaceName, L"Consolas"); // Choose your font
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
return 1;
}
void admin::admin_login(){
here1:
string admin_username,admin_password;
char ch;
cout<<"\n\n\t\t";
for(int i=0;i<90;i++)
{
cout<<char(205);
}
cout<<"\t\t\t\t\t\t\t Admin Login Page: ";
cout<<"\n\t\t";
for(int i=0;i<90;i++)
{
cout<<char(205);
}
cout<<"\n\n\t\t\t Enter username: ";cin>>admin_username;cout<<"\n\n";
cout<<"\t\t\t Enter password: ";
while ((ch = _getch()) != '\r') {
if (ch == '\b') {
if (!admin_password.empty()) {
admin_password.pop_back();
cout << "\b \b";
}
} else {
admin_password += ch;
cout << '*';
}
}
string aname,apass;
ifstream pass("admin.txt");
pass.seekg(0,ios::beg);
bool authenticated = false;
while (pass >> aname >> apass) {
if (aname == admin_username && apass == admin_password) {
authenticated = true;
break; // Match found, no need to continue searching
}
}
if (authenticated) {
cout << "\n\n\n\t\t\tAuthentication successful.\n\n";
cout<<"\n\n\t\t\t\tLogging ";
for(int i=0;i<5;i++)
{
cout<<".";
Sleep(500);
}
admin_page();
}
else
{
char a;
MessageBeep(MB_OK);
cout<<"\n\n\t\t\t\tAuthentication failed.\n\n";
cout<<"\n\n\t\t\t\tDo you want to try again?";
cout<<"\n\n\t\t\t\tEnter y for yes and n for no\n";
cout<<"\n\n\t\t\t\t";
a=getch();
if(a=='Y'||a=='y'){
system("cls");
goto here1;
}
else if(a=='N'||a=='n'){
login_page();
}
else{
exit(0);
}
}
}
void user::user_login(){
here1:
char ch;
cout<<"\n\n\t\t";
for(int i=0;i<90;i++)
{
cout<<char(205);
}
cout<<"\t\t\t\t\t\t\t User Login Page: ";
cout<<"\n\t\t";
for(int i=0;i<90;i++)
{
cout<<char(205);
}
cout<<"\n\n\t\t\t Enter username: ";cin>>user_username;cout<<"\n\n";
cout<<"\t\t\t Enter password: ";
while ((ch = _getch()) != '\r') {
if (ch == '\b') {
if (!user_password.empty()) {
user_password.pop_back();
cout << "\b \b";
}
} else {
user_password += ch;
cout << '*';
}
}
string uname,upass;
ifstream pass("useridpw.txt");
pass.seekg(0,ios::beg);
bool authenticated = false;
while (pass >> uname >> upass) {
if (uname == user_username && upass == user_password) {
authenticated = true;
break; // Match found, no need to continue searching
}
}
if (authenticated) {
cout << "\n\n\n\t\t\tAuthentication successful.\n\n";
cout<<"\n\n\t\t\t\tLogging ";
for(int i=0;i<4;i++)
{
cout<<".";
Sleep(500);
}
user_page();
}
else
{
char a;
MessageBeep(MB_OK);
cout << "\n\n\t\t\tAuthentication failed.\n\n";
cout<<"\n\t\t\tDo you want to try again?";
cout<<"\n\n\t\t\tEnter y for yes and n for no\n";
cout<<"\n\n\t\t\t";
a=getch();
if(a=='Y'||a=='y'){
system("cls");
goto here1;
}
else if(a=='N'||a=='n'){
login_page();
}
else{
exit(0);
}
}
}
void admin::create_user(){
system("cls");
cout<<"\n\n\t\t";
for(int i=0;i<90;i++)
{
cout<<char(205);
}
cout<<"\t\t\t\t\t\t\t Admin Mode: ";
cout<<"\n\t\t";
for(int i=0;i<90;i++)
{
cout<<char(205);
}
cout<<"\n\t\tFor Account Creating";
cout<<"\n\n\t\tChoose type of Account you want to create : ";
cout<<"\n\t\t\t[1] Fixed Deposit Account";
cout<<"\n\t\t\t[2] Current Account";
cout<<"\n\t\t";
actp:
cin>>acc_type;
if(acc_type!=1&&acc_type!=2){
cout<<"\n\t\tInvalid input.Please enter again. \n";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
goto actp;
}
cout<<"\n\n\t\tEnter Your first name : ";
cin>>first_name;
cout<<"\n\t\tEnter Your last name : ";
cin>>last_name;
cout<<"\n\t\tEnter Your Grandfather's first name : ";
cin>>grandfather_firstname;
cout<<"\n\t\tEnter Your Grandfather's last name : ";
cin>>grandfather_lastname;
cout<<"\n\t\tEnter Your Father's first name : ";
cin>>father_firstname;
cout<<"\n\t\tEnter Your Father's last name : ";
cin>>father_lastname;
cout<<"\n\t\tEnter Your Mother's first name : ";
cin>>mother_firstname;
cout<<"\n\t\tEnter Your Mother's last name : ";
cin>>mother_lastname;
cout<<"\n\t\tEnter Your Date of Birth(year/month/day) in B.S. : ";
DOB();
cout<<"\n\t\tEnter Your province name : ";
cin>>province ;
cout<<"\n\t\tEnter Your District name : ";
cin>>district;
cout<<"\n\t\tEnter Your Municipality name : ";
cin>>municipality;
cout<<"\n\t\tEnter Your ward number : ";
do {
if (cin >> ward) {
// Input is a valid integer
break;
} else {
cout << "\n\t\tInvalid input! Please enter an integer." << endl;
cin.clear(); // Clear the error state
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // Clear the input buffer
cout<<"\n\t\t";
}
} while (true);
cout<<"\n\t\tEnter Your tole name : ";
cin>>tole;
cout<<"\n\t\tEnter Your Gender (m/f) : ";
while (!(cin >> gender) || (gender != 'M' && gender != 'm' && gender != 'F' && gender != 'f')) {
std::cout << "\n\t\tInvalid input! Please enter 'M' or 'F'.\n";
std::cin.clear(); // Clear the error state
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // Clear the input buffer
std::cout << "\n\t\tEnter your gender (M or F): ";
}
cout<<"\n\t\tEnter your Mobile number : ";
phone_number();
cout<<"\n\t\tEnter your Email address : ";
us_email();
bank_accnumber();
bank_accbalance();
search_display();
yaha:
cout<<"\n\n\t\t Do you want to edit? (y || n) ";
char jawaf;
jawaf=getch();
if(jawaf=='y'||jawaf=='Y'){
create_user();
}
else if(jawaf=='n'||jawaf=='N'){
//now writting this data in a file
ofstream userdat;
userdat.open("projectuserdata.txt",ios::app);
userdat<<first_name;
userdat<<" ";
userdat<<last_name;
userdat<<" ";
userdat<<"+977-"<<mob_num;
userdat<<" ";
userdat<<bank_balance;
userdat<<" ";
userdat<<bank_accnum;
userdat<<" ";
userdat<<grandfather_firstname;
userdat<<" ";
userdat<<grandfather_lastname;
userdat<<" ";
userdat<<father_firstname;
userdat<<" ";
userdat<<father_lastname;
userdat<<" ";
userdat<<mother_firstname;
userdat<<" ";
userdat<<mother_lastname;
userdat<<" ";
userdat<<year;
userdat<<" ";
userdat<<month;
userdat<<" ";
userdat<<day;
userdat<<" ";
userdat<<province;
userdat<<" ";
userdat<<district;
userdat<<" ";
userdat<<municipality;
userdat<<" ";
userdat<<ward;
userdat<<" ";
userdat<<tole;
userdat<<" ";
userdat<<gender;
userdat<<" ";
userdat<<email;
userdat<<endl;
userdat.close();
//for creating text file for specific person to track transaction
//***************yaaaaaaaaaa****************************************************************
ofstream off;
string filename;
filename="+977-"+mob_num+".txt";
off.open(filename);
// off<<first_name;
// off<<" ";
// off<<last_name;
// off<<" ";
// off<<"+977-"<<mob_num;
// off<<" ";
off<<"d ";
off<<bank_balance<<" ";
time_t tim=time(0);
tm* atime=localtime(&tim);
int cyear=atime->tm_year+1900;
/* 1900 is added in year because in tm structure the year is counted fromm 1900 so the counted year should be
added wirh 1900 to get current year */
int cmonth=atime->tm_mon+1;//since month represent from 0(jan) to 11(dec)
int cday=atime->tm_mday;
int chour=atime->tm_hour;
int cminu=atime->tm_min;
off<<cyear<<" "<<cmonth<<" "<<cday<<" "<<chour<<" "<<cminu;
off<<endl;
off.close();
//setting user id pw
string us_name,us_pass;
us_name=mob_num;
us_pass=first_name;
ofstream userid;
userid.open("useridpw.txt",ios::out|ios::app);
userid<<us_name;
userid<<" ";
userid<<us_pass;
userid<<endl;
userid.close();
cout<<"\n\t\t\tAccount created sucessfully";
}
else{
cout<<"\n\t\tInvalid input.Please enter again.";
goto yaha;
}
getch();
admin_page();
}
void admin::admin_page(){
system("cls");
cout<<"\n\n\t\t"<<char(201);
for(int i=0;i<80;i++)
{
cout<<char(205);
}
cout<<char(187)<<endl;
for(int i=0;i<1;i++)
{
cout<<"\t\t"<<char(186)<<"\t\t\t\t\t\t\t\t\t\t "<<char(186)<<endl;
}
cout<<"\t\t"<<char(186)<<"\t\t\t Admin Page \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t Select Task \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [1] Create Account \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [2] Search Acc \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [3] Tasks \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [4] Logout \t\t "<<char(186)<<endl;
for(int i=0;i<11;i++)
{
cout<<"\t\t"<<char(186)<<"\t\t\t\t\t\t\t\t\t\t "<<char(186)<<endl;
}
cout<<"\t\t"<<char(200);
for(int i=0;i<80;i++)
{
cout<<char(205);
}
cout<<char(188)<<endl<<endl;
cout<<char(205);
char ch=getch();
switch(ch){
case '1':{
create_user();
break;
}
case '2':{
search_user();
break;
}
case '3':{
tasks();
break;
}
case '4':{
system("cls");
cout<<"\n\n\t\tLogging out";
for(int i=0;i<5;i++)
{
cout<<".";
Sleep(500);
}
login_page();
}
default:{
cout<<"\n\n\t\tInvalid Input. Try Again ";
cout<<"\n\t\t( Press any key to continue )";
getch();
admin_page();
}
}
}
void user::user_page(){
system("cls");
cout<<"\n\n\t\t"<<char(201);
for(int i=0;i<80;i++)
{
cout<<char(205);
}
cout<<char(187)<<endl;
for(int i=0;i<1;i++)
{
cout<<"\t\t"<<char(186)<<"\t\t\t\t\t\t\t\t\t\t "<<char(186)<<endl;
}
cout<<"\t\t"<<char(186)<<"\t\t\t User Page \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t Select Task \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [1] My Information \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [2] Transaction History \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [3] Change Password \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [4] Logout \t\t "<<char(186)<<endl;
for(int i=0;i<11;i++)
{
cout<<"\t\t"<<char(186)<<"\t\t\t\t\t\t\t\t\t\t "<<char(186)<<endl;
}
cout<<"\t\t"<<char(200);
for(int i=0;i<80;i++)
{
cout<<char(205);
}
cout<<char(188)<<endl<<endl;
cout<<char(205);
char ch=getch();
switch(ch){
case '1':{
user_information();
break;
}
case '2':{
transaction_history();
break;
}
case '3':{
change_password();
// password();
break;
}
case '4':{
system("cls");
cout<<"\n\n\t\tLogging out";
for(int i=0;i<5;i++)
{
cout<<".";
Sleep(500);
}
login_page();
}
default:{
cout<<"\n\n\t\tInvalid Input. Try Again ";
cout<<"\n\t\t( Press any key to continue )";
getch();
user_page();
}
}
}
void admin::search_user(){
system("cls");
cout<<"\n\n\t\t"<<char(201);
for(int i=0;i<88;i++)
{
cout<<char(205);
}
cout<<char(187);
cout<<"\n\t\t"<<char(186)<<"\t\t\t Admin Mode : \t\t\t "<<char(186);
cout<<"\n\t\t"<<char(186);
for(int i=0;i<88;i++)
{
cout<<char(205);
}
cout<<char(186);
cout<<"\n\t\t"<<char(186)<<"\t\t\t Search Page \t\t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [1] Search By Name \t\t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [2] Search By Account Number \t\t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [3] Back \t\t\t "<<char(186)<<endl;
for(int i=0;i<11;i++)
{
cout<<"\t\t"<<char(186)<<"\t\t\t\t\t\t\t\t\t\t\t "<<char(186)<<endl;
}
cout<<"\t\t"<<char(200);
for(int i=0;i<88;i++)
{
cout<<char(205);
}
cout<<char(188)<<endl;
char ch;
bool validInput = false;
while (!validInput) {
ch = getch();
if (ch=='1'||ch=='2'||ch=='3') {
validInput = true;
}
else {
cout << "Invalid input. Please enter a valid integer: ";
}
}
switch(ch){
case '1':{
string uname;
cout<<"\n\t\tEnter User 1st name : ";
cin>>uname;
search_by_name(uname);
break;
}
case '2':{
string unumber;
cout<<"\n\t\tEnter User Bank Account Number : ";
cin.clear();
cin>>unumber;
search_by_acc_num(unumber);
break;
}
case '3':{
admin_page();
}
}
}
void admin::search_by_name(const string& name) {
ifstream userdat;
userdat.open("projectuserdata.txt", ios::in);
int count=0;
bool found = false;
string line;
while (getline(userdat, line)) {
stringstream iss(line);
iss >> first_name;
if (name == first_name) {
count++;
iss >> last_name >> mob_num >> bank_balance >> bank_accnum >> grandfather_firstname >> grandfather_lastname
>> father_firstname >> father_lastname >> mother_firstname >> mother_lastname >> year >> month >> day
>> province >> district >> municipality >> ward >> tole >> gender >> email;
// Display the information of the matching user
//cout<<"\n\t\t\t\tUser : "<<count;
//this->search_display();
// Display other user information here...
//cout << endl;
}
}
userdat.close();
ifstream ser;
ser.open("projectuserdata.txt",ios::in);
string sline;
if(count>=2){
string num;
cout<<"\n\t\tEnter mobile number :\n\t\t+977-";
cin>>num;
string totnum="+977-"+num;
cout<<totnum;
while (getline(ser, sline)) {
stringstream iss(sline);
iss >> first_name>>last_name>>mob_num;
if ( totnum == mob_num ) {
found = true;
iss >> bank_balance >> bank_accnum >> grandfather_firstname >> grandfather_lastname
>> father_firstname >> father_lastname >> mother_firstname >> mother_lastname >> year >> month >> day
>> province >> district >> municipality >> ward >> tole >> gender >> email;
this->search_display();
}
}
}
ser.close();
if (!found) {
cout << "\n\t\tNo user found with that name" << endl;
}
char ans;
cout<<"\n\n\t\tDo you want to continue (y/n) ? ";
cin>>ans;
if(ans=='y'||ans=='Y')
search_user();
else if(ans=='n'||ans=='N')
admin_page();
else
cout<<"\n\t\tInvalid input";
}
void admin::search_by_acc_num(const string& number){
ifstream userdat;
userdat.open("projectuserdata.txt", ios::in);
string line;
bool found=false;
while (getline(userdat, line)) {
stringstream ss(line);
// Read the bank_accnumber from the stringstream and compare it
ss >> first_name >> last_name >> mob_num >> bank_balance >> bank_accnum;
if (bank_accnum == number) {
found = true ;
// Read the rest of the data from the stringstream
ss >> grandfather_firstname >> grandfather_lastname >> father_firstname >> father_lastname >> mother_firstname >> mother_lastname >> year >> month >> day >> province >> district >> municipality >> ward >> tole >> gender >> email;
this->search_display();
}
}
userdat.close();
if (!found) {
cout << "\n\t\tNo user found with that Account Number" << endl;
}
char ans;
h1:
cout<<"\n\n\t\tDo you want to continue (y/n) ? ";
//cin>>ans;
ans=getch();
if(ans=='y'||ans=='Y')
search_user();
else if(ans=='n'||ans=='N')
admin_page();
else
cout<<"\n\t\tInvalid input.Try again.";
goto h1;
}
void admin::tasks(){
system("cls");
cout<<"\n\n\t\t"<<char(201);
for(int i=0;i<80;i++)
{
cout<<char(205);
}
cout<<char(187)<<endl;
for(int i=0;i<1;i++)
{
cout<<"\t\t"<<char(186)<<"\t\t\t\t\t\t\t\t\t\t "<<char(186)<<endl;
}
cout<<"\t\t"<<char(186)<<"\t\t\t Admin \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t Select Task \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [1] Deposit Money \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [2] Withdraw Money \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [3] Delete Account \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t \t\t "<<char(186)<<endl;
cout<<"\t\t"<<char(186)<<"\t\t\t [4] Go Back \t\t "<<char(186)<<endl;
for(int i=0;i<11;i++)
{
cout<<"\t\t"<<char(186)<<"\t\t\t\t\t\t\t\t\t\t "<<char(186)<<endl;
}
cout<<"\t\t"<<char(200);
for(int i=0;i<80;i++)
{
cout<<char(205);
}
cout<<char(188)<<endl<<endl;
cout<<char(205);
char ch=getch();
switch(ch){
case '1':{
string name,accnum;
double money;
cout<<"\n\n\t\tEnter user 1st name : ";
cin>>name;
cout<<"\n\t\tEnter Account number : ";
cin>>accnum;
cout<<"\n\t\tEnter amount of money to be deposited : ";
cin>>money;
deposit(name,accnum,money);
tasks();
break;
}
case '2':{
string name,accnum;
double money;
cout<<"\n\n\t\tEnter user 1st name : ";
cin>>name;
cout<<"\n\t\tEnter Account number : ";
cin>>accnum;
bool validinput=false;
while(!validinput){
cout<<"\n\t\tEnter amount of money to withdraw : ";
if(cin>>money){
validinput=true;
// Check for any remaining characters in the input buffer
if (std::cin.peek() != '\n') {
validinput = false;
std::cout << "Invalid input. Please enter a valid amount." << std::endl;
// Clear the input buffer to remove invalid input
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
}
else{
cout << "\t\tInvalid input. Please enter a valid amount." << std::endl;
// Clear the error flag to allow further input attempts
std::cin.clear();
// Clear the input buffer to remove invalid input
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
}
//cin>>money;
withdraw(name,accnum,money);
tasks();
break;
}
case '3':{
string name,accnum;
cout<<"\n\n\t\tEnter user 1st name : ";
cin>>name;
cout<<"\n\t\tEnter Account number : ";
cin>>accnum;
delete_acc(name,accnum);
tasks();
break;
break;
}
case '4':{
admin_page();
break;
}
default:{
cout<<"\n\n\t\tInvalid Input. Try Again ";
cout<<"\n\t\t( Press any key to continue )";
getch();
tasks();
break;
}
}
}
void admin::deposit(const string& name, const string& accnum, double money) {
ifstream userdat;
ofstream updatedUserdat;
userdat.open("projectuserdata.txt", ios::in);