-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_SBL_Features.h
More file actions
566 lines (502 loc) · 18.7 KB
/
Copy path_SBL_Features.h
File metadata and controls
566 lines (502 loc) · 18.7 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
#include "accountClass.h"
#include <windows.h>
#include <iomanip>
#include <conio.h>
#include <cstdlib>
/* ========================================================
**********************_FUNCTION_PROTOTYPES******************
========================================================*/
void SIGN_IN_OR_SIGN_UP(account *, int, account &);
void loginPage(char &);
account Login(string &, int &, account *, const int);
account createNewAccount(account *&, int &);
void successfullyCreatedAccount(account &);
void secondPage(account &, char &, account *, int &);
void loanRequest(account &);
void requestLoan(account *, int &, account &, char, bool);
void transictionProcess(account *, int &, account &, char, bool);
void deleteAccount(account *, int &, account &, char, bool, bool &);
/* ==============================================================================================
***************************************_FUNCTIONS_BODY******************************************
================================================================================================*/
/* ========================================================
************************_LOGIN_PAGE_FUNCTION***************
========================================================*/
void loginPage(char &login)
{
spaces1();
spaces2();
cout << "\t\t\t\t\t\t LOGIN " << endl;
spaces2();
cout << "\t\t -----------------------------------------------------------------------------" << endl;
cout << "\t\t | *If you have already an account then press \'L\' for login your account : |" << endl;
cout << "\t\t | *If you don't have an account then press \'C\' for create your account : |" << endl;
cout << "\t\t -----------------------------------------------------------------------------" << endl;
login = getch();
login = tolower(login);
//_INPUT_VALIDATION
while (login != 'l' && login != 'c')
{
cout << "\t\tError->Invalid Input :" << endl;
cout << "\t\tPlease enter the valid input as \'L\' or \'C\':" << endl;
login = getch();
login = tolower(login);
}
}
/* ========================================================
************************LOGIN_FUNCTION*********************
========================================================*/
account Login(string &username, int &pin, account *accs, const int noOfAccounts)
{
bool flag = false;
account temp;
do
{
cout << endl;
cout << "\t\t ----------------------------" << endl;
cout << "\t\t Enter username:";
getline(cin, username);
cout << "\t\t Enter pin :";
cin >> pin;
cout << "\t\t ----------------------------" << endl;
// CALCULATING_USERNAME
for (int i = 0; i < noOfAccounts && flag == false; i++)
{
if ((accs + i)->getUserName() == username && (accs + i)->getPin() == pin)
{
flag = true;
temp = *(accs + i);
}
}
//_INPUT_VALIDATION
if (flag == false)
{
cout << "\t >>Error: Such Account does'nt exist. Enter valid Information again :" << endl;
cin.ignore();
}
} while (flag == false);
if (flag == true)
{
return temp;
}
}
/* ========================================================
*********************CALCULATIONS_FUNCTION*****************
========================================================*/
void successfullyCreatedAccount(account &newAccount)
{
newAccount.calculateUserName();
newAccount.calculateTotalBalance();
newAccount.calculateTotalIncome();
newAccount.calculateTotalOutcome();
newAccount.calculateTotalInterest();
}
/* ========================================================
*****************_CREATE_NEW_ACCOUNT_FUNCTION**************
========================================================*/
account createNewAccount(account *&accs, int &noOfAccounts)
{
system("cls");
spaces1();
spaces2();
cout << "\t\t Create an account : " << endl;
spaces2();
account newAccount;
char boolDeposit;
newAccount.createAccount();
boolDeposit = getch();
boolDeposit = tolower(boolDeposit);
switch (boolDeposit)
{
case 'y':
{
spaces2();
cout << "\t\t Do your first movement by depositing at least $200:";
newAccount.setSize(1);
newAccount.setMovementsValue();
//_INPUT_VALIDATION
while (*(newAccount.getMovementsAddress() + 0) < 200)
{
cout << "\t\t Error : Low balance you must have deposit at leat $200 :";
newAccount.setMovementsValue();
}
successfullyCreatedAccount(newAccount);
break;
}
case 'n':
{
successfullyCreatedAccount(newAccount);
break;
}
}
//_ADDING_NEW_ACCOUNT_TO_THE_*ACCOUNTS*_ARRAY
account *tempAccounts = new account[noOfAccounts + 1];
for (int i = 0; i < noOfAccounts; i++)
{
*(tempAccounts + i) = *(accs + i);
}
delete[] accs;
accs = tempAccounts;
accs[noOfAccounts] = newAccount;
noOfAccounts++;
return newAccount;
}
/* ========================================================
************************_SECOND_PAGE_FUNCTION***************
========================================================*/
void secondPage(account ¤tUser, char &login, account *accounts, int &noOfAccounts, bool &flag)
{
bool exit = false;
do
{
if (flag == true)
{
system("cls");
flag = false;
}
char options;
spaces1();
spaces2();
cout << "\t\t\t\t\t WELCOME ! " << currentUser.getName() << endl;
spaces2();
cout << "Total Balance : " << currentUser.getTotalBalance() << endl;
spaces2();
cout << "\t\t\t\t *OPTIONS* " << endl;
cout << "\t\t ------------------------------------------" << endl;
cout << "\t\t| Press \'R\' for request loan |" << endl;
cout << "\t\t| Press \'T\' for transfer money |" << endl;
cout << "\t\t| Press \'S\' for sort movements |" << endl;
cout << "\t\t| Press \'D\' for delete account |" << endl;
cout << "\t\t| Press \'E\' for log out |" << endl;
cout << "\t\t ------------------------------------------" << endl;
spaces2();
cout << "\t\t\t *YOUR ACCOUNT DETAILS* " << endl;
spaces2();
currentUser.getData();
options = getch();
options = tolower(options);
//_INPUT_VALIDATION
while (options != 'r' && options != 't' && options != 's' && options != 'd' && options != 'e')
{
cout << "\t\t Error : Invalid Input ! " << endl;
cout << "\t\t Please enter the valid input :" << endl;
options = getch();
options = tolower(options);
}
switch (options)
{
case 'r':
{
requestLoan(accounts, noOfAccounts, currentUser, login, flag);
break;
}
case 't':
{
transictionProcess(accounts, noOfAccounts, currentUser, login, flag);
break;
}
case 'd':
{
deleteAccount(accounts, noOfAccounts, currentUser, login, flag, exit);
break;
}
case 's':
{
currentUser.sortMovements();
system("cls");
secondPage(currentUser, login, accounts, noOfAccounts, flag);
break;
}
case 'e':
{
spaces2();
cout<<"\t\t\t Logging out..........."<<endl;
Sleep(2*1000);
system("cls");
cin.ignore();
exit = true;
SIGN_IN_OR_SIGN_UP(accounts, noOfAccounts, currentUser);
break;
}
}
} while (exit == false);
}
/* ========================================================
****************_SIGN_IN_OR_SIGN_UP_FUNCTION****************
========================================================*/
void SIGN_IN_OR_SIGN_UP(account *accounts, int noOfAccounts, account ¤tUser)
{
string username;
int pin;
char login;
bool flag = false;
loginPage(login);
switch (login)
{
case 'l':
{
currentUser = Login(username, pin, accounts, noOfAccounts);
successfullyCreatedAccount(currentUser);
flag = true;
spaces2();
cout << "\t\t\t Loading......" << endl;
Sleep(2 * 1000);
secondPage(currentUser, login, accounts, noOfAccounts, flag);
break;
}
case 'c':
{
currentUser = createNewAccount(accounts, noOfAccounts);
system("cls");
cout << "\t\tCongratulations ! You have successfully created your first Account :" << endl;
secondPage(currentUser, login, accounts, noOfAccounts, flag);
break;
}
}
}
/* ========================================================
**********************_REQUEST_LOAN_FUNCTION***************
========================================================*/
void requestLoan(account *accounts, int &noOfAccounts, account ¤tUser, char login, bool flag)
{
// INPUT_VALIDATION
if (currentUser.getTotalBalance() >= 500)
{
double amount = 0;
spaces2();
cout << "\t\t\t Enter the loan amount you want to request from bank : ";
cin >> amount;
// INPUT_VALIDATION
while (amount < 0)
{
cout << "\t\t\t Invalid Input : Please Enter the valid input (amount should be a positive value ) :";
cin >> amount;
}
//_SLEEP_FUNCTION
spaces2();
cout << "\t\t\t\t Your request is in progress........." << endl;
Sleep(3 * 1000);
system("cls");
cout << "\t\t\t You request is approved ,You got $" << amount << " of loan from Salik Bank Limited (SBL) " << endl;
// CALCULATE_CURRENT_USER_INDEX
int currentIndex = 0;
for (int i = 0; i < noOfAccounts; i++)
{
if ((accounts + i)->getUserName() == currentUser.getUserName())
{
currentIndex = i;
break;
}
}
// DEEPY_COPY_CHANGING_CURRENTUSER_MOVEMNETS
account *tempAccounts = new account[noOfAccounts];
for (int i = 0; i < noOfAccounts; i++)
{
*(tempAccounts + i) = *(accounts + i);
}
int tempSize = (tempAccounts + currentIndex)->getSize();
double *tempMov = new double[tempSize + 1];
for (int i = 0; i < tempSize; i++)
{
*(tempMov + i) = *((tempAccounts + currentIndex)->getMovementsAddress() + i);
}
*(tempMov + tempSize) = amount;
delete[](tempAccounts + currentIndex)->getMovementsAddress();
(tempAccounts + currentIndex)->setMovementsAddress(tempMov);
(tempAccounts + currentIndex)->setSize((tempAccounts + currentIndex)->getSize() + 1);
delete[] accounts;
accounts = tempAccounts;
currentUser = *(accounts + currentIndex);
successfullyCreatedAccount(currentUser);
secondPage(currentUser, login, accounts, noOfAccounts, flag);
}
else
{
system("cls");
cout << "\t\t Low Balance ! For requesting Loan you must have at least $500 in your account. " << endl;
secondPage(currentUser, login, accounts, noOfAccounts, flag);
}
}
/* ========================================================
**********************_TRANSICTION_MONEY_FUNCTION***************
========================================================*/
void transictionProcess(account *accounts, int &noOfAccounts, account ¤tUser, char login, bool flag)
{
bool accountExist = false;
int indexReciever = 0;
int currentIndex = 0;
double amountTransfer = 0;
string usernameTransfer = "";
spaces2();
cout << "\t\t\t Enter the amount that you want to transfer :";
cin >> amountTransfer;
// INPUT_VALIDATION
while (currentUser.getTotalBalance() - amountTransfer < 200)
{
cout << "Sorry Sir ! You cannot transfer more than $" << currentUser.getTotalBalance() - 200 << ", At least your bank account has $200 in it." << endl;
cout << "\t\t\t Again enter the amount that you want to transfer :";
cin >> amountTransfer;
}
do
{
bool selfTransfer = false;
cout << "\t\t\t Enter the username of the account ,whom you want to transfer money:";
cin >> usernameTransfer;
// CALCULATING_CURRENT_USER_Index_AND_RECEIVER_INDEX
if (usernameTransfer == currentUser.getUserName())
{
selfTransfer = true;
}
for (int i = 0; i < noOfAccounts; i++)
{
if ((accounts + i)->getUserName() == usernameTransfer && (accounts + i)->getUserName() != currentUser.getUserName())
{
accountExist = true;
indexReciever = i;
break;
}
}
for (int i = 0; i < noOfAccounts; i++)
{
if ((accounts + i)->getUserName() == currentUser.getUserName())
{
currentIndex = i;
break;
}
}
// INPUT_VALIDATION
if (accountExist == true && selfTransfer == false)
{
spaces2();
cout << "\t\t\t Transiction is in process...." << endl;
Sleep(3 * 1000);
system("cls");
cout << "\t\t\t SUCCESSFULLY TRANSFERED ,You transfered $" << amountTransfer << " to the account " << usernameTransfer << endl;
// DEEP_COPY::_ADDING_WITHRAWL_IN_THE_CURRENT_USER
amountTransfer = amountTransfer * (-1);
account *tempAccounts = new account[noOfAccounts];
for (int i = 0; i < noOfAccounts; i++)
{
*(tempAccounts + i) = *(accounts + i);
}
int tempSize = (tempAccounts + currentIndex)->getSize();
double *tempMov = new double[tempSize + 1];
for (int i = 0; i < tempSize; i++)
{
*(tempMov + i) = *((tempAccounts + currentIndex)->getMovementsAddress() + i);
}
*(tempMov + tempSize) = amountTransfer;
delete[](tempAccounts + currentIndex)->getMovementsAddress();
(tempAccounts + currentIndex)->setMovementsAddress(tempMov);
(tempAccounts + currentIndex)->setSize((tempAccounts + currentIndex)->getSize() + 1);
delete[] accounts;
accounts = tempAccounts;
currentUser = *(accounts + currentIndex);
successfullyCreatedAccount(currentUser);
// DEEP_COPY::_ADDING_DEPOSITED_IN_THE_RECEIVER_ACCOUNT_MOVEMENTS
amountTransfer = abs(amountTransfer);
account *tempAccounts2 = new account[noOfAccounts];
for (int i = 0; i < noOfAccounts; i++)
{
*(tempAccounts2 + i) = *(accounts + i);
}
int tempSize2 = (tempAccounts2 + indexReciever)->getSize();
double *tempMov2 = new double[tempSize2 + 1];
for (int i = 0; i < tempSize2; i++)
{
*(tempMov2 + i) = *((tempAccounts + indexReciever)->getMovementsAddress() + i);
}
*(tempMov2 + tempSize2) = amountTransfer;
delete[](tempAccounts2 + indexReciever)->getMovementsAddress();
(tempAccounts2 + indexReciever)->setMovementsAddress(tempMov2);
(tempAccounts2 + indexReciever)->setSize((tempAccounts2 + indexReciever)->getSize() + 1);
delete[] accounts;
accounts = tempAccounts2;
successfullyCreatedAccount(*(accounts + indexReciever));
secondPage(currentUser, login, accounts, noOfAccounts, flag);
}
if (accountExist == false)
{
cout << "\t\t\t Error: Such Account does'nt exist : " << endl;
}
if (selfTransfer == true)
{
spaces2();
cout << "\t\tError :You could not transfer money to yourself:" << endl;
spaces2();
}
} while (accountExist == false);
}
/* ========================================================
**********************_DELETE_ACCOUNT_FUNCTION***************
========================================================*/
void deleteAccount(account *accounts, int &noOfAccounts, account ¤tUser, char login, bool flag, bool &exit)
{
spaces2();
string deleteUsername;
int deleteUserPin;
bool found = false;
char confirm;
do
{
cout << "\t\t To delete your account enter your username or pin code:" << endl;
cout << "\t\t\t Enter your username:";
cin >> deleteUsername;
cout << "\t\t\t Enter your pincode: ";
cin >> deleteUserPin;
if (currentUser.getUserName() == deleteUsername && currentUser.getPin() == deleteUserPin)
{
found = true;
cout << "\t\t\t Are you sure to delete your account (y/n): ";
confirm = getch();
confirm = tolower(confirm);
// INPUT_VALIDATION
while (confirm != 'y' && confirm != 'n')
{
cout << "\t\t\t Invalid input : Please enter the valid input as (y/n) :";
confirm = getch();
confirm = tolower(confirm);
}
switch (confirm)
{
case 'y':
{
// DEEP_DELETION_ACCOUNT_FROM_THE_ACCOUNTS_ARRAY
int loc = 0;
account *tempAccountsDelete = new account[noOfAccounts - 1];
for (int i = 0; i < noOfAccounts; i++)
{
if ((accounts + i)->getPin() != currentUser.getPin())
{
*(tempAccountsDelete + loc) = *(accounts + i);
loc++;
}
}
delete[] accounts;
accounts = tempAccountsDelete;
noOfAccounts--;
// DELETING....
spaces2();
cout << "\t\t\t Deleting your account........" << endl;
Sleep(3 * 1000);
system("cls");
cin.ignore();
exit = true;
cout << "\t\t\t\t YOUR ACCOUNT HAS BEEN DELETED SUCCESSFULLY " << endl;
SIGN_IN_OR_SIGN_UP(accounts, noOfAccounts, currentUser);
break;
}
case 'n':
{
system("cls");
secondPage(currentUser, login, accounts, noOfAccounts, flag);
break;
}
}
}
else
{
cout << "\t\t You enter the worng username or pincode : Try Again : " << endl;
}
} while (found == false);
}