-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmain.cpp
482 lines (459 loc) · 15.9 KB
/
main.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
476
477
478
479
480
481
482
#include <iostream>
#include <string>
#include <cstring>
#include <conio.h>
#include<vector>
using namespace std;
int total_saving_accounts = 0;
int total_current_accounts = 0;
class account
{
public :
string name_of_account_holder;
string name_of_joint_account_holder;
long long int account_number;
int balance;
// int withdraw;
// int deposit;
string type_of_account;
string pin;
public :
//In case of single holder account
account(string accholdername,int bal,string typeofacc,string pc)
{
account_number = rand()%100000 + 1000000000;
name_of_account_holder = accholdername;
balance = bal;
type_of_account = typeofacc;
pin = pc;
name_of_joint_account_holder = "No Joint Holder in this account";
}
//In case of multiple holder account
account(string accholdername,string jointholdername,int bal,string typeofacc,string pc)
{
account_number = rand()%100000 + 1000000000;
name_of_account_holder = accholdername;
name_of_joint_account_holder = jointholdername;
balance = bal;
type_of_account = typeofacc;
pin = pc;
}
//Function to calculate interest
float calculate_interest(){
//assuming interest rate is 16%
float interest_rate = 0.16;
float interest = balance * interest_rate;
return interest;
}
};
vector<account>accts;
void display_details(long long int accnum)
{
bool acc_exists = false;
for(auto it : accts)
{
if(it.account_number==accnum)
{
acc_exists = true;
cout<<"\nAccount Number : "<<it.account_number;
cout<<"\nAccount Holder Name : "<<it.name_of_account_holder;
cout<<"\nJoint Holder Name : "<<it.name_of_joint_account_holder;
cout<<"\nBalance in your account : "<<it.balance;
cout<<"\nType of Account : "<<it.type_of_account;
}
}
if(acc_exists == false){
cout<<"Account doesn't exists with given Account Number.";
exit(0);
}
}
bool create_account(vector<account>&accts)
{
system("cls");
string accholder_name;
cout<<"\nENTER YOUR DETAILS HERE : ";
cout<<"\nName of Account Holder : ";
cin>>accholder_name;
string str;
cout<<"\nDo you want to have joint holder account? Type YES/NO : ";
cin>>str;
string joint_holder;
if(str=="YES")
{
cout<<"Enter the name of Joint Holder : ";
cin>>joint_holder;
}
string pin;
cout<<"\nEnter the pin : ";
cin>>pin;
string typeofacc;
cout<<"\nEnter the type of account : ";
int choice;
cout<<"1 - Savings Account\n";
cout<<"2 - Current Account\n";
cout<<"Enter your choice here : ";
cin>>choice;
if(choice==1)
typeofacc = "Savings";
else
typeofacc = "Current";
int balance;
cout<<"\nEnter the balance you want to have initially in your account : ";
cin>>balance;
//========SINGLE HOLDER ACCOUNT===========//
//If it is savings account
if(typeofacc=="Savings" && str == "YES"){
account ob(accholder_name,joint_holder,balance,typeofacc,pin);
total_saving_accounts++;
accts.push_back(ob);
std::cout << "\t\t|-----------------------------------------------|" << "\n";;
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| ACCOUNT CREATED SUCCESSFULLY |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
display_details(ob.account_number);
return true;
}
//If it is current account and balance is insufficient
if(typeofacc=="Current" && balance < 10000 && str == "YES")
{
std::cout << "\t\t|-----------------------------------------------|" << "\n";;
std::cout << "\t\t| INSUFFICIENT BALANCE |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
return false;
}
//Current account with sufficient balance
else{
account ob(accholder_name,joint_holder,balance,typeofacc,pin);
accts.push_back(ob);
total_current_accounts++;
std::cout << "\t\t|-----------------------------------------------|" << "\n";;
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| ACCOUNT CREATED SUCCESSFULLY |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
display_details(ob.account_number);
return true;
}
//========JOINT HOLDER ACCOUNT===========//
//If it is savings account
if(typeofacc=="Savings" && str == "NO"){
account ob(accholder_name,balance,typeofacc,pin);
total_saving_accounts++;
accts.push_back(ob);
std::cout << "\t\t|-----------------------------------------------|" << "\n";;
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| ACCOUNT CREATED SUCCESSFULLY |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
display_details(ob.account_number);
return true;
}
//If it is current account and balance is insufficient
if(typeofacc=="Current" && balance < 10000 && str == "NO")
{
std::cout << "\t\t|-----------------------------------------------|" << "\n";;
std::cout << "\t\t| INSUFFICIENT BALANCE |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
return false;
}
//Current account with sufficient balance
else{
account ob(accholder_name,balance,typeofacc,pin);
accts.push_back(ob);
total_current_accounts++;
std::cout << "\t\t|-----------------------------------------------|" << "\n";;
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| ACCOUNT CREATED SUCCESSFULLY |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
display_details(ob.account_number);
return true;
}
}
long long int accnumber;
bool change_pin()
{
long long int accnum;
cout<<"Enter your account number : ";
cin>>accnum;
bool acc_exists = false;
for(auto it : accts)
{
if(it.account_number==accnum)
{
acc_exists = true;
string newpin;
string oldpin;
cout<<"Enter the old pin : ";
cin>>oldpin;
if(oldpin==it.pin)
{
cout<<"Enter new pin : ";
cin>>newpin;
it.pin = newpin;
display_details(it.account_number);
accnumber = it.account_number;
return true;
}
else{
cout<<"Invalid Pin. Try Again";
return false;
}
}
}
if(acc_exists == false){
cout<<"Account doesn't exists with given Account Number.";
return false;
}
}
bool deposit_into_account()
{
long long int accnum;
cout<<"Enter your account number : ";
cin>>accnum;
bool acc_exists = false;
for(auto it : accts)
{
if(it.account_number==accnum)
{
acc_exists = true;
string pinfordepo;
cout<<"Enter the pin : ";
cin>>pinfordepo;
if(pinfordepo==it.pin)
{
int deposit_amount;
cout<<"Enter the amount you want to deposit : ";
cin>>deposit_amount;
it.balance = it.balance+deposit_amount;
cout<<"Your Updated details : ";
display_details(it.account_number);
return true;
}
else{
cout<<"Invalid Pin. Try Again";
return false;
}
}
}
if(acc_exists == false){
cout<<"Account doesn't exists with given Account Number.";
return false;
}
}
bool withdraw_from_account()
{
long long int accnum;
cout<<"Enter your account number : ";
cin>>accnum;
bool acc_exists = false;
for(auto it : accts)
{
if(it.account_number==accnum)
{
acc_exists = true;
string pinfordepo;
cout<<"Enter the pin : ";
cin>>pinfordepo;
if(pinfordepo==it.pin)
{
int withdrawl_amount;
cout<<"Enter the amount you want to deposit : ";
cin>>withdrawl_amount;
if(it.balance-withdrawl_amount > 0)
{
it.balance = it.balance - withdrawl_amount;
cout<<"Your Updated details : ";
display_details(it.account_number);
return true;
}
else{
cout<<"Oooopssss!!!! Insufficient Balance";
}
}
else{
cout<<"Invalid Pin. Try Again";
return false;
}
}
}
if(acc_exists == false){
cout<<"Account doesn't exists with given Account Number.";
return false;
}
}
bool balance_inquiry()
{
long long int accnum;
cout<<"Enter your account number : ";
cin>>accnum;
bool acc_exists = false;
for(auto it : accts)
{
if(it.account_number==accnum)
{
cout<<"The balance in your account is : "<<it.balance;
return true;
}
}
if(acc_exists == false){
cout<<"Account doesn't exists with given Account Number.";
return false;
}
}
bool close_account()
{
long long int accnum;
cout<<"Enter your account number : ";
cin>>accnum;
bool acc_exists = false;
int count = 0;
for(auto it : accts)
{
count++;
if(it.account_number==accnum)
{
accts.erase(accts.begin()+count);
return true;
}
}
if(acc_exists == false){
cout<<"Account doesn't exists with given Account Number.";
return false;
}
}
bool view_account_details()
{
for(auto it : accts)
{
display_details(it.account_number);
}
return true;
}
void admin_menu()
{
int option;
system("cls");
std::cout << "\t\t|-----------------------------------------------|" << "\n";
std::cout << "\t\t| Choose your option: |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| 1) View Total Number of Accounts |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| 2) View Account Details |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
cin>>option;
switch(option)
{
case 1:
cout<<"Total Number of Accounts : "<<accts.size();
break;
case 2:
view_account_details();
break;
default:
cout<<"Invalid Option";
break;
}
}
void user_menu()
{
system("cls");
std::cout << "\t\t|-----------------------------------------------|" << "\n";
std::cout << "\t\t| Choose your option: |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| 1) Create a New Account |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| 2) Change your pin |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| 3) Deposit Money |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| 4) Withdraw Money |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| 5) Balance Inquiry |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| 6) Close Account |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| 7) Display Account |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| 8) Exit |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
int choice;
do{
cout<<"\nEnter your choice : ";
cin>>choice;
if(choice==1){
bool ans = create_account(accts);
}
else if(choice==2)
{
bool pinchanged = change_pin();
}
else if(choice==3)
{
bool successfuldeposit = deposit_into_account();
}
else if(choice==4)
{
bool successfulwithdraw = withdraw_from_account();
}
else if(choice==5)
{
bool successinquiry = balance_inquiry();
}
else if(choice==6)
{
bool successful_close_account = close_account();
}
else if(choice==7)
{
long long int account_number;
cout<<"Enter the account number for details to be displayed : ";
cin>>account_number;
display_details(account_number);
}
else if(choice==8)
{
exit(0);
}
}while(choice!=8);
}
void welcome()
{
std::cout << "\t\t|-----------------------------------------------|" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t| WELCOME TO YRNCOLLO BANKING SYSTEM |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
std::cout << "\t\t|\t Choose your option:\t |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t|\t\t 1) ADMINISTRATOR |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t|\t\t 2) USER |" << "\n";
std::cout << "\t\t| |" << "\n";
std::cout << "\t\t|\t\t 3) EXIT |" << "\n";
std::cout << "\t\t|-----------------------------------------------|" << "\n";
int choice;
std::cout << "\n\nEnter: ";
std::cin >> choice;
if(choice==1)
admin_menu();
else if(choice==2){
user_menu();
display_details(accnumber);
}
else if(choice==3)
exit(0);
else
system("pause");
}
int main()
{
welcome();
return 0;
}