-
Notifications
You must be signed in to change notification settings - Fork 1
/
Banking.cpp
475 lines (446 loc) · 9.66 KB
/
Banking.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
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
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<cstdio>
#include<ctype.h>
#include<string.h>
#include<windows.h>
using namespace std;
int check(long accno);
class Accounts
{
long accno;
char pass[20];
long double amount;
char lasttran[10];
protected:
char accname[25];
public:
Accounts()
{
amount=0;
strcpy(lasttran,"none");
}
long getacno()
{
return accno;
}
char* getname()
{
return accname;
}
char* getpass()
{
return pass;
}
long double getamt()
{
return amount;
}
void getdata()
{ ac:
cout<<"Select account no. : ";
cin>>accno;
if(!check(accno))
{
goto ac;
}
cin.ignore();
again:
cout<<"Enter account name: ";
cin.getline(accname,25);
if(accname[0]>='0'&&accname[0]<='9')
{
cout<<endl<<"Account name can not begin with a digit! "<<endl;
goto again;
}
cin.ignore();
setp:
cout<<"Set a strong password: ";
cin>>pass;
if(strlen(pass)<8)
{
cout<<endl<<"Password too short!"<<endl;
goto setp;
}
char repass[20];
cout<<"Re enter password: ";
cin>>repass;
if(strcmp(repass,pass))
{
cout<<endl<<"Passwords do not match! \n please re-Enter \n";
goto setp;
}
}
void showdet()
{
cout<<"Account number: "<<accno<<endl;
cout<<"Account name: "<<accname<<endl;
cout<<"Current amount: "<<amount<<endl;
}
void withdraw()
{long amt;
cout<<"How much amount do you want to withdraw? :";
cin>>amt;
if(amount-amt>0)
{amount-=amt;
cout<<"Transaction was successful, remaining balance= "<<amount;}
else{cout<<"Not sufficient balance in the account! ";cout<<endl<<"Amount: "<<amount<<endl;}
}
void setpass(char pas[20])
{
strcpy(pass,pas);
}
void setlas(char state[4])
{
strcpy(lasttran,state);
}
int cmppass(char pas[20])
{
int a=strcmp(pass,pas);
return !a;
}
void welcome()
{
cout<<endl<<"Welcome "<<accname<<endl;
}
void deposit()
{long amt;
cout<<"How much money do you want to deposit? :";
cin>>amt;
amount+=amt;
cout<<"Transaction was successful,balance= "<<amount;
}
int cmplasttran(char state[4])
{
int r=strcmp(state,lasttran);
return !r;
}
};
class person:public Accounts
{
char name[25];
char desig;
public:
person()
{
strcpy(name,accname);
}
void getdetail()
{
getdata();
des:
cout<<"Enter Designation(A/N): ";
cin>>desig;
if((desig!='A' && desig!='a') && (desig!='N' && desig!='n'))
{
cout<<endl<<"please enter A/N "<<endl;
toupper(desig);
goto des;
}
}
char deg()
{
return desig;
}
}S;
int check(long accno)
{
ifstream chek("accounts.dat",ios::binary|ios::in);
person c;
do
{
chek.read((char*)&c,sizeof(c));
if(c.getacno()==accno)
{
cout<<endl<<"This account no. already exists! please choose another one! \n";
Sleep(3000);
return 0;
}
}while(chek);
chek.close();
return 1;
}
void accdel(long accn)
{
fstream acc, nw;
acc.open("accounts.dat",ios::binary|ios::in|ios::out);
nw.open("new.dat",ios::binary|ios::app|ios::in);
person p;
do
{
acc.read((char*)&p,sizeof(p));
if(p.getacno()==accn)
{
}
else
{
nw.write((char*)&p,sizeof(p));
}
}while(acc);
acc.close();
nw.close();
remo:
int rem=remove("accounts.dat");
if(rem!=0){goto remo;}
rena:
int ren=rename("new.dat","accounts.dat");
if(ren!=0){goto rena;}
}
void listup()
{
person p;
fstream i("accounts.dat",ios::binary|ios::in);
ofstream o("accounts.txt",ios::out);
do
{
i.read((char*)&p,sizeof(p));
o<<endl<<"Account no "<<p.getacno()<<endl;
o<<"Name: "<<p.getname()<<" ;"<<endl;
}while(i);
i.close();
o.close();
}
int main()
{
int choice;
cout<<"\n\n\n \t\t\t Bank \n\n \t\t \t Management \n\n \t\t \t System \n\n\n";
cout<<" Made by Dhairya Joshi \n";
cout<<" School: St.Xavier's High School \n";
Sleep(6000);
system("CLS");
start:
cout<<"1.Admin login"<<endl;
cout<<"2.User login"<<endl;
cout<<"3.Terminate program "<<endl;
cout<<"Enter choice: ";cin>>choice;
if(choice==1)
{long acc;person A;
fstream a;
a.open("accounts.dat",ios::in|ios::binary);
cout<<endl<<"Enter Account number: ";cin>>acc;
bool found=true;
do
{
a.read((char*)&A,sizeof(A));
if(acc==A.getacno()&& (A.deg()=='A' || A.deg()=='a') )
{
char p[20];found=false;
A.welcome();
cout<<endl<<"Enter password: ";cin>>p;
if(!strcmp(p,A.getpass()))
{int choice=0;
adstart:
cout<<endl<<"What do you want to do? ";
cout<<endl<<"1.Add new account "<<endl;
cout<<"2.Delete an account "<<endl;
cout<<"3.Show all accounts "<<endl;
cout<<"4.Exit to main menu "<<endl;
cin>>choice;
if(choice==1)
{
person P;
fstream ac("accounts.dat",ios::binary|ios::app);
P.getdetail();
ac.write((char*)&P,sizeof(P));
ac.close();
listup();
cout<<endl<<"Account added successfully! "<<endl;
P.showdet();
Sleep(3000);
system("CLS");
goto adstart;
}
else if(choice==2)
{long acn;bool found=true;person P;a.close();
cout<<endl<<"Enter account no you want to delete: ";cin>>acn;
ifstream file("accounts.dat",ios::binary|ios::in);
do
{
file.read((char*)&P,sizeof(P));
if(acn==P.getacno())
{found=false;
P.showdet();
file.close();
cout<<endl<<"Are you sure you want to delete this account?(y/n): ";
char o;
cin>>o;
if(o=='y' || o=='Y')
{
accdel(acn);
cout<<endl<<"Account deleted successfully! ";
listup();
Sleep(3000);
system("CLS");
goto adstart;
}
else{cout<<endl<<"Account not deleted! ";Sleep(3000);
system("CLS");goto adstart;}
}
}while(file&&found);
if(found)
{cout<<endl<<"No such account could be found! ";Sleep(3000);
system("CLS");goto adstart;}
}
else if(choice==4)
{
system("CLS");
goto start;
}
else if(choice==3)
{char word;
ifstream lfile("accounts.txt");
listup();
int cond=1;
do
{
lfile.get(word);
if(word==';')
{word='\0';
cond=!cond;
}
if(cond)
{
cout<<word;
}
}while(lfile);
lfile.close();
}
Sleep(7000);
system("CLS");
goto adstart;
}
else{cout<<"Wrong password entered!";Sleep(3000);
system("CLS");goto start;}
}
}while(found&&a);
a.close();
if(found)
{
cout<<"No such account could be found! "<<endl;
Sleep(3000);
system("CLS");
goto start;}
}
else if(choice==2)
{
long ac;person A;bool found=true;
cout<<endl<<"Enter your Account no: ";
cin>>ac;
fstream user("accounts.dat",ios::binary|ios::in);
do
{
user.read((char*)&A,sizeof(A));
if(ac==A.getacno()&&'N'==A.deg())
{
user.close();
found=false;
char p[20];
A.welcome();
cout<<"Enter password: ";
cin>>p;
if(!strcmp(p,A.getpass()))
{int choice=0;
userstart:
cout<<endl<<"What would you like to do? "<<endl;
cout<<"1.Add amount "<<endl;
cout<<"2.Withdraw amount "<<endl;
cout<<"3.Show amount "<<endl;
cout<<"4.Change password "<<endl;
cout<<"5.Exit to main menu "<<endl;
cin>>choice;
if(choice==1)
{
A.deposit();
accdel(ac);
ofstream newa("accounts.dat",ios::binary|ios::app);
newa.write((char*)&A,sizeof(A));
newa.close();
Sleep(6000);
system("CLS");
goto userstart;
}
else if(choice==2)
{
A.withdraw();
accdel(ac);
ofstream newa("accounts.dat",ios::binary|ios::app);
newa.write((char*)&A,sizeof(A));
newa.close();
Sleep(6000);
system("CLS");
goto userstart;
}
else if(choice==3)
{
cout<<"Amount in account is :"<<A.getamt();
Sleep(3000);
system("CLS");
goto userstart;
}
else if(choice==4)
{char oldp[20];char newp[20];
cout<<endl<<"Enter current password: ";
cin>>oldp;
if(A.cmppass(oldp))
{
setp:
cout<<endl<<"Set New password: ";
cin>>newp;
if(strlen(newp)<8)
{
cout<<endl<<"Password too short!"<<endl;
goto setp;
}
cout<<endl<<"Re- enter new password: :";
cin>>oldp;
if(!strcmp(oldp,newp))
{
accdel(ac);
A.setpass(newp);
ofstream newa("accounts.dat",ios::binary|ios::app);
newa.write((char*)&A,sizeof(A));
newa.close();
cout<<endl<<"Password updated successfully! "<<endl;
Sleep(6000);
system("CLS");
goto userstart;
}
else{cout<<endl<<"The password doesn't match! ";
Sleep(6000);
system("CLS");
goto userstart;
}
}
else{
cout<<endl<<"Incorrect password entered! ";
Sleep(6000);
system("CLS");
goto userstart;
}
}
else if(choice==5)
{
system("CLS");
goto start;
}
}
else{cout<<endl<<"Wrong password entered! "<<endl;Sleep(3000);
system("CLS");goto start;}
}
}while(found&&user);
if(found)
{user.close();
cout<<endl<<"No such user account found! "<<endl;
Sleep(3000);
system("CLS");
goto start;
}
}
else if(choice==3)
{
exit(0);
}
else{cout<<endl<<"Wrong input!" ;Sleep(2000);system("CLS");goto start;}
return 0;
}