-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccountmng.cpp
More file actions
590 lines (548 loc) · 12.4 KB
/
Copy pathaccountmng.cpp
File metadata and controls
590 lines (548 loc) · 12.4 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
//============================================================================
// Name : Project.cpp
// Author : Asher Farhan (19i-0618)
// Version :
// Copyright :
// Description : Bank ATM in C++, Ansi-style
//============================================================================
#include<iostream>
#include<iomanip>
#include<string>
#include <unistd.h>
#include<fstream>
using namespace std;
int flag = 0; // Global Variable
class Screen // Screen Classs
{
public :
void displayWelcome();
void EnterAccountNo();
void EnterPinNo();
void AccountVerify();
void AccountnotVerify();
void MainMenu();
void balance();
void WithdrawMenu();
void depositamount();
};
void Screen :: displayWelcome()
{
cout<<"\n================================================================================== "<<endl;
cout<<"\n---------------------------- WELCOME TO THE ATM ------------------------------- "<<endl;
cout<<"\n================================================================================== "<<endl;
}
void Screen :: EnterAccountNo()
{
cout<<"\nPlease Enter Your Account No : "<<endl;
}
void Screen :: EnterPinNo()
{
cout<<"\nPlease Enter Your PIN No : "<<endl;
}
void Screen :: AccountVerify()
{
cout<<"\n------------------- Your Account has Been Verified --------------------- "<<endl;
}
void Screen :: AccountnotVerify()
{
cout<<"\n------------------ Your Account has not Been Verified --------------------"<<endl;
}
void Screen :: MainMenu()
{
cout<<"\n------------------- Main Menu -------------------- "<<endl;
cout<<"\n1 - View my Balance "<<"\t\t2 - WithDraw Cash "<<endl;
cout<<"\n3 - Deposit Cash "<<"\t\t4 - Exit "<<endl;
cout<<"\nEnter a Choice : "<<endl;
}
void Screen :: balance()
{
cout<<"\nYour Current Account Balance is = ";
}
void Screen :: WithdrawMenu()
{
cout<<"\n---------------- WithDrawl Options ------------------- "<<endl;
cout<<"\n1 - $20 "<<"\t\t2 - $40 "<<endl;
cout<<"\n3 - $60 "<<"\t\t4 - $100 "<<endl;
cout<<"\n5 - $200 "<<"\t\t6 - Cancel Transaction "<<endl;
cout<<"\nChoose a WithDrawl Option (1 - 6) "<<endl;
}
void Screen :: depositamount()
{
cout<<"\nEnter the Deposit Amount ( In CENTS ) or Press 0 to Cancel the Transaction : "<<endl;
}
class Keypad // Keypad Class
{
public :
string getAccountNo();
string getPinNo();
int getMenuOption();
int getDepositAmount();
int getWithdrawlOption();
};
string Keypad :: getAccountNo()
{
string accNo;
getline(cin,accNo);
return accNo;
}
string Keypad :: getPinNo()
{
string pinNo;
getline(cin,pinNo);
return pinNo;
}
int Keypad :: getMenuOption()
{
int meOp;
cin>>meOp;
return meOp;
}
int Keypad :: getWithdrawlOption()
{
int wdop;
cin>>wdop;
return wdop;
}
int Keypad :: getDepositAmount()
{
int deAm;
cin>>deAm;
return deAm;
}
class CashDispenser // Cash Dispenser Class
{
public :
void returncash();
int checkamount(int,int);
};
void CashDispenser :: returncash()
{
cout<<"\n-------------- The Amount has been WithDrawled Successfully --------------- "<<endl;
cout<<"\n !!!! Dont Forget to Take Your Amount.... Thanks !!!!! "<<endl;
}
int CashDispenser :: checkamount(int amount , int bal)
{
int rem = 0;
if(amount > bal)
{
rem = 1;
}
return rem;
}
class DepositSlot // Deposit Slot Class
{
public :
int depositcash(int,double);
};
int DepositSlot :: depositcash(int bal , double amount)
{
int rem = 0;
int tem;
tem = amount / 100;
rem = bal + tem;
return rem;
}
class Account // Account Class
{
protected :
string AccountNo;
string PinNo;
double BankBalance;
public :
void setAccountNo(string);
void setPinNo(string);
void setBankBalance(double);
string getEnteredAccountNo() ;
string getEnteredPinNo() ;
int getEnteredBankBalance() ;
};
//-------------------------- Setter or Mutator Functions --------------------------
void Account :: setAccountNo(string accountNo)
{
this -> AccountNo = accountNo;
}
void Account :: setPinNo(string pinNo)
{
this -> PinNo = pinNo;
}
void Account :: setBankBalance(double balance)
{
this -> BankBalance = balance;
}
// ------------------------- Accessor or Getter Functions -------------------
string Account :: getEnteredAccountNo()
{
return AccountNo;
}
string Account :: getEnteredPinNo()
{
return PinNo;
}
int Account :: getEnteredBankBalance()
{
return BankBalance;
}
/////////////////// Balance Inquiry Class inherited from Account Class /////////////////////////
class BalanceInquiry : public Account
{
private:
Screen scr; // Composition
public:
int InquireBalance();
void displaybalance();
};
int BalanceInquiry :: InquireBalance()
{
return BankBalance;
}
void BalanceInquiry :: displaybalance()
{
scr.balance();
}
/////////////////// WithDrawl Class inherited from Account Class /////////////////////////
class WithDrawl : public Account
{
private :
Screen scr;
CashDispenser dispense; // Composition
public :
void displaywithdrawl();
int withdraw(int amount);
int check(int amo);
};
void WithDrawl :: displaywithdrawl()
{
scr.WithdrawMenu();
}
int WithDrawl :: withdraw(int amount)
{
int temp;
temp = getEnteredBankBalance() - amount;
return temp;
}
int WithDrawl :: check(int amo)
{
return dispense.checkamount(amo, getEnteredBankBalance());
}
/////////////////// Deposit Class inherited from Account Class /////////////////////////
class Deposit : public Account
{
private :
DepositSlot Ds; // Composition
Screen scr;
public :
void displayamount();
int depositamount(double);
};
void Deposit :: displayamount()
{
scr.depositamount();
}
int Deposit :: depositamount(double amount)
{
cout<<"\nYour Amount Has been Deposited Successfully "<<endl;
return Ds.depositcash(getEnteredBankBalance() , amount);
}
/////////////////// ATM Class inherited from Account Class /////////////////////////
class ATM : public Account
{
private:
Screen scr;
Keypad key;
CashDispenser cashdis;
DepositSlot deposit;
public:
int getverifyAccountNo(string []);
int getverifyPinNo(string []);
void AccountVerifyMessage();
void AccountnotVerifyMessage();
};
int ATM :: getverifyAccountNo(string account [4])
{
flag = 0;
int temp = 0;
for(int i=0;i<4;i++)
{
if(getEnteredAccountNo() == account[i])
{
temp = 1;
break;
}
flag++;
}
return temp;
}
int ATM :: getverifyPinNo(string PIN [4])
{
int temp1 = 0;
for(int i=0;i<4;i++)
{
if(getEnteredPinNo() == PIN[flag])
{
temp1 = 1;
break;
}
}
return temp1;
}
void ATM :: AccountVerifyMessage()
{
scr.AccountVerify();
}
void ATM :: AccountnotVerifyMessage()
{
scr.AccountnotVerify();
}
/////////////////////////////////////// DRIVER FUNCTION IMPLEMENTATION //////////////////////////////////////
int main()
{
string acc,pin;
int bal = 100;
// Account details of user 1
string useracc1 = "21345";
string userpin1 = "54312";
int userbal1 = 9000;
// Account Details of User 2
string useracc2 = "73983";
string userpin2 = "38937";
int userbal2 = 7000;
// Account Details of User 3
string useracc3 = "92807";
string userpin3 = "70829";
int userbal3 = 5000;
string name;
cout<<"--------------------- Creating New Account --------------------- "<<endl;
cout<<"\nEnter your Full Name : "<<endl;
getline(cin,name);
cout<<"\nEnter the Account No : "<<endl;
getline(cin,acc);
cout<<"\nEnter the Pin : "<<endl;
getline(cin,pin);
cout<<"\nYour Account has Been Successfully Created "<<endl;
ofstream ofile,ofile1,ofile2;
ifstream ifile,ifile1,ifile2;
ofile.open("Account No.txt");
ifile.open("Account No.txt");
ofile1.open("Pin No.txt");
ifile1.open("Pin No.txt");
ofile2.open("Account Balance.txt");
ifile2.open("Account Balance.txt");
ofile<<acc<<endl;
ofile<<useracc1<<endl;
ofile<<useracc2<<endl;
ofile<<useracc3<<endl;
ofile1<<pin<<endl;
ofile1<<userpin1<<endl;
ofile1<<userpin2<<endl;
ofile1<<userpin3<<endl;
ofile2<<bal<<endl;
ofile2<<userbal1<<endl;
ofile2<<userbal2<<endl;
ofile2<<userbal3<<endl;
Screen S;
Keypad K;
Account A;
ATM atm;
BalanceInquiry BI;
WithDrawl Wd;
CashDispenser Cd;
Deposit D;
string account[4],Apin[4];
int balance[4];
int Averify;
int Pverify;
int opt;
double accbal;
int count2 = 0;
while(! ifile2.eof()) // reading balance from file
{
ifile2>>balance[count2];
count2++;
}
do
{
S.displayWelcome();
S.EnterAccountNo();
string accNo = K.getAccountNo();
atm.setAccountNo(accNo);
S.EnterPinNo();
string PinNo = K.getPinNo();
atm.setPinNo(PinNo);
int count = 0,count1 = 0;
while(! ifile.eof()) // reading account no from file
{
ifile>>account[count];
count++;
}
while(! ifile1.eof()) // reading pin no from file
{
ifile1>>Apin[count1];
count1++;
}
Averify = atm.getverifyAccountNo(account);
Pverify = atm.getverifyPinNo(Apin);
if(Averify == 1 && Pverify == 1)
{
accbal = balance[flag];
atm.setBankBalance(accbal);
atm.AccountVerifyMessage();
S.MainMenu();
opt = K.getMenuOption();
while(opt == 1 || opt == 2 || opt == 3) // Loop for Processing Main Menu
{
accbal = balance[flag];
if(opt == 1)
{
BI.setBankBalance(accbal);
BI.displaybalance();
cout<<BI.InquireBalance()<<endl;
}
if(opt == 2)
{
int temp;
do // Loop for Processing WithDrawl Menu
{
int opt1;
Wd.displaywithdrawl();
opt1 = K.getWithdrawlOption();
if(opt1 == 1)
{
int amo;
int res;
Wd.setBankBalance(accbal);
amo = 20;
temp = Wd.check(amo);
if(temp == 1)
{
cout<<"\nERROR... The Withdrawl Amount is Greater than the Bank Balance "<<endl;
}
else if(temp == 0)
{
res = Wd.withdraw(amo);
Cd.returncash();
balance[flag] = res;
}
}
else if(opt1 == 2)
{
int amo;
int res;
Wd.setBankBalance(accbal);
amo = 40;
temp = Wd.check(amo);
if(temp == 1)
{
cout<<"\nERROR... The Withdrawl Amount is Greater than the Bank Balance "<<endl;
}
else if(temp == 0)
{
res = Wd.withdraw(amo);
Cd.returncash();
balance[flag] = res;
}
}
else if(opt1 == 3)
{
int amo;
int res;
Wd.setBankBalance(accbal);
amo = 60;
temp = Wd.check(amo);
if(temp == 1)
{
cout<<"\nERROR... The Withdrawl Amount is Greater than the Bank Balance "<<endl;
}
else if(temp == 0)
{
res = Wd.withdraw(amo);
Cd.returncash();
balance[flag] = res;
}
}
else if(opt1 == 4)
{
int amo;
int res;
Wd.setBankBalance(accbal);
amo = 100;
temp = Wd.check(amo);
if(temp == 1)
{
cout<<"\nERROR... The Withdrawl Amount is Greater than the Bank Balance "<<endl;
}
else if(temp == 0)
{
res = Wd.withdraw(amo);
Cd.returncash();
balance[flag] = res;
}
}
else if(opt1 == 5)
{
int amo;
int res;
Wd.setBankBalance(accbal);
amo = 200;
temp = Wd.check(amo);
if(temp == 1)
{
cout<<"\nERROR... The Withdrawl Amount is Greater than the Bank Balance "<<endl;
}
else if(temp == 0)
{
res = Wd.withdraw(amo);
Cd.returncash();
balance[flag] = res;
}
}
else if(opt1 == 6)
{
temp = 0;
cout<<"\n------- Your Transaction has been Cancelled --------- "<<endl;
}
} while(temp == 1);
}
else if(opt == 3)
{
double a;
int b;
D.setBankBalance(accbal);
D.displayamount();
a = K.getDepositAmount();
if(a == 0)
{
cout<<"\n---------- The Transaction Has Been Cancelled ------------ "<<endl;
}
if(a != 0)
{
cout<<"\nEntering the Deposit Envelope in the Deposit Slot "<<endl;
sleep(2);
b = D.depositamount(a);
balance[flag] = b;
}
}
S.MainMenu();
opt = K.getMenuOption();
}
cout<<"\n!!! ------------------ Updating the Bank Data Base -------------------- !!! "<<endl;
cout<<"\n ------------------------- THANK YOU ------------------------------- "<<endl;
ofile2<<"\nThe Updated Accounts Balance are : "<<endl;
for(int i=0;i<4;i++) // Writing the Updated Accounts Balance in File
{
ofile2<<balance[i]<<endl;
}
cin.ignore();
}
else
{
atm.AccountnotVerifyMessage();
}
} while(Averify == 0 || Pverify == 0 || opt == 4);
ofile.close();
ofile1.close();
ofile2.close();
ifile.close();
ifile1.close();
ifile2.close();
return 0;
}