forked from elqabasy/Scholarship-Database
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.cpp
More file actions
1198 lines (1061 loc) · 45.5 KB
/
project.cpp
File metadata and controls
1198 lines (1061 loc) · 45.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 <algorithm>
#include <limits>
#include <vector>
using namespace std;
// Classes Pre-Definitions
class person;
class account;
class bankAccount;
class studyFinderAccount;
class university;
// Colour codes
const string RESET = "\033[0m";
const string RED = "\033[31m";
const string GREEN = "\033[32m";
const string YELLOW = "\033[33m";
const string BLUE = "\033[34m";
const string MAGENTA = "\033[35m";
const string CYAN = "\033[36m";
const string WHITE = "\033[37m";
const string BOLD = "\033[1m";
// Essential Functions
inline void clearInput() {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
inline void clearScreen() {
system("cls");
}
inline void displayHeader(const string& title) {
clearScreen();
cout << BOLD << BLUE << "=-=-=-=-=-=-=- " << title << " -=-=-=-=-=-=-=-\n" << RESET << "\n";
}
void displayOptions(const vector<string>& options) {
for (size_t i = 0; i < options.size(); ++i) {
if (i == options.size() -1){
cout << BOLD << CYAN << "|[0]| " << RESET << options[i] << '\n';
break;
}
cout << BOLD << CYAN << "|[" << i+1 << "]| " << RESET << options[i] << '\n';
}
cout << "\n";
}
void displayErrorMessage(unsigned short msg, const vector<string>& messages) {
if (msg < messages.size()) {
cout << RED << messages[msg] << RESET << "\n\n";
}
}
unsigned short choose(unsigned short from, unsigned short to) {
unsigned short choice;
while (true) {
cout << "|[USER-INPUT]| Select an option (" << from << "-" << to << "): ";
cin >> choice;
if (cin.fail()) {
// If input is not a number
clearInput();
cout << "|[CONSOLE]| Invalid Input, please enter a number between " << from << " and " << to << ".\n";
} else if (choice >= from && choice <= to) {
break;
} else {
cout << "|[CONSOLE]| Invalid Input, please enter a number between " << from << " and " << to << ".\n";
}
}
return choice;
}
// Enums
enum region { Africa = 1, Europe, America, Asia };
enum gender { Male = false, Female = true };
enum degree_level { Highschool = 1, Undergraduate, Postgraduate };
enum english_level { A1 = 1, A2, B1, B2, C1, C2 };
enum study_programme { ComputerScience = 1, Engineering, Business, Arts, Media, Law};
// Implementations of Input Function of the Enums
region inputRegion() {
int choice;
while (true) {
cout << "Select region (1: Africa, 2: Europe, 3: America, 4: Asia): ";
cin >> choice;
if (!cin.fail() && choice >= Africa && choice <= Asia) {
return static_cast<region>(choice);
} else {
clearInput();
cout << "Invalid input. Please enter a number between 1 and 4.\n";
}
}
}
gender inputGender() {
int choice;
while (true) {
cout << "Select gender (0: Male, 1: Female): ";
cin >> choice;
if (!cin.fail() && (choice == Male || choice == Female)) {
return static_cast<gender>(choice);
} else {
clearInput();
cout << "Invalid input. Please enter 0 for Male or 1 for Female.\n";
}
}
}
degree_level inputDegreeLevel() {
int choice;
while (true) {
cout << "Select degree level (1: Highschool, 2: Undergraduate, 3: Postgraduate): ";
cin >> choice;
if (!cin.fail() && choice >= Highschool && choice <= Postgraduate) {
return static_cast<degree_level>(choice);
} else {
clearInput();
cout << "Invalid input. Please enter a number between 1 and 3.\n";
}
}
}
english_level inputEnglishLevel() {
int choice;
while (true) {
cout << "Select English level (1: A1, 2: A2, 3: B1, 4: B2, 5: C1, 6: C2): ";
cin >> choice;
if (!cin.fail() && choice >= A1 && choice <= C2) {
return static_cast<english_level>(choice);
} else {
clearInput();
cout << "Invalid input. Please enter a number between 1 and 6.\n";
}
}
}
study_programme inputStudyProgramme() {
int choice;
while (true) {
cout << "Select study programme (1: Computer Science, 2: Engineering, 3: Business, 4: Arts, 5: Media): ";
cin >> choice;
if (!cin.fail() && choice >= ComputerScience && choice <= Media) {
return static_cast<study_programme>(choice);
} else {
clearInput();
cout << "Invalid input. Please enter a number between 1 and 5.\n";
}
}
}
// Classes
class person {
protected:
string real_name;
gender p_gender;
region p_region;
unsigned short age;
float gpa;
degree_level degree_lvl;
english_level english_lvl;
public:
// Default Constructor
person()
: real_name(""), p_gender(gender::Male), p_region(region::Africa), age(0), gpa(0), degree_lvl(degree_level::Highschool), english_lvl(english_level::A1) {}
// Constructor
person(const string& name, gender g, region r, unsigned short a, float gpa, degree_level dl, english_level el)
: real_name(name), p_gender(g), p_region(r), age(a), gpa(gpa), degree_lvl(dl), english_lvl(el) {}
// Constructor for derived classes
person(region r, float gpa, degree_level dl, english_level el)
: real_name(""), p_gender(gender::Male), p_region(r), age(0), gpa(gpa), degree_lvl(dl), english_lvl(el) {}
friend bool qualificationCheck(const studyFinderAccount& user, const university& org);
virtual void display() const {}
};
class account {
protected:
string user_name;
string user_password;
unsigned int user_id;
public:
// Constructor
account(const string& username = "", const string& password = "", unsigned int id = 0)
: user_name(username), user_password(password), user_id(id) {}
friend bool qualificationCheck(const studyFinderAccount& user, const university& org);
};
class bankAccount : public account {
private:
double balance = 0;
static int counter;
public:
// Constructor
bankAccount(const string& un = "", const string& pw = "", double bal = 0.0)
: account(un, pw, 100100 + counter), balance(bal) {
counter += 100;
}
// Main Methods
unsigned short deposit(double amount) {
if (amount < 5) {
return 1;
} else if (amount > 10000) {
return 2;
} else {
balance += amount;
return 3;
}
}
unsigned short withdraw(double amount) {
if (amount < 5) {
return 1;
} else if (amount > 10000) {
return 2;
} else {
balance -= amount;
return 3;
}
}
unsigned short transfer(double amount, bankAccount& account) {
if (amount < 5) {
return 1;
} else if (amount > balance) {
return 2;
} else {
balance -= amount;
account.balance += amount;
return 4;
}
}
void display() const {
cout << "|[BANK]| Account Name : " << user_name << '\n'
<< " | Account ID : " << user_id << '\n'
<< " | Balance : " << balance << "$\n\n";
}
// Set Methods
void setName(const string& name) { user_name = name; }
void setNumber(unsigned int num) { user_id = num; }
void setBalance(double b) { balance = b; }
void setPinCode(const string& pc) { user_password = pc; }
// Get Methods
string getName() const { return user_name; }
unsigned int getNumber() const { return user_id; }
double getBalance() const { return balance; }
string getPinCode() const { return user_password; }
};
class studyFinderAccount : public person, public account {
private:
bankAccount personal_account;
public:
// Constructors
studyFinderAccount(const string& un = "", const string& pw = "")
: account(un, pw) {}
studyFinderAccount(const string& un, const string& pw, unsigned int id, const string& rn,
gender g, region r, unsigned short a, float gpa,
degree_level dl, english_level el, const bankAccount& ba)
: person(rn, g, r, a, gpa, dl, el), account(un, pw, id), personal_account(ba) {}
// Set Methods
void setUsername(const string& un) { user_name = un; }
void setPassword(const string& pw) { user_password = pw; }
void setRealName(const string& rn) { real_name = rn; }
void setRegion(region r) { p_region = r; }
void setGender(gender g) { p_gender = g; }
void setAge(unsigned short a) { age = a; }
void setDegreeLvl(degree_level dl) { degree_lvl = dl; }
void setEnglishLvl(english_level el) { english_lvl = el; }
void setGPA(float g) { gpa = g; }
void setBank(const bankAccount& pb) { personal_account = pb; }
// Get Methods
string getUsername() const { return user_name; }
string getPassword() const { return user_password; }
string getRealName() const { return real_name; }
region getRegion() const { return p_region; }
gender getGender() const { return p_gender; }
unsigned short getAge() const { return age; }
degree_level getDegreeLvl() const { return degree_lvl; }
english_level getEnglishLvl() const { return english_lvl; }
float getGPA() const { return gpa; }
bankAccount getBank() const { return personal_account; }
};
class university: public person {
private:
string name;
string desc;
study_programme programme;
double tuition_fees;
static int counter;
bankAccount uniBank;
public:
// Constructor
university(const string& _name = "", region _region = Africa, const string& _desc = "", study_programme _prog = {ComputerScience}, degree_level _degree_lvl = Highschool, english_level _english_lvl = A1,
double _tuition_fees = 0.0, float _gpa = 0.0)
: person(_region, _gpa, _degree_lvl, _english_lvl),
name(_name), desc(_desc), programme(_prog), tuition_fees(_tuition_fees), uniBank(name, "", 100000 + counter) {
++counter;
}
// Comparison operator of acceptance chance
bool operator >(const university& uni) const {
unsigned short score1 = 0, score2 = 0;
(english_lvl < uni.english_lvl) ? ++score1 : ++score2;
(gpa < uni.gpa) ? ++score1 : ++score2;
return (score1 <= score2);
}
bool operator <(const university& uni) const {
unsigned short score1 = 0, score2 = 0;
(english_lvl > uni.english_lvl) ? ++score1 : ++score2;
(gpa > uni.gpa) ? ++score1 : ++score2;
return (score1 >= score2);
}
// Display in list
void display() const override {
cout << "Uni: " << name << '\n'
<< " | Region: " << p_region << '\n'
<< " | Degree: " << degree_lvl << '\n'
<< " | Programme: " << programme << '\n'
<< " | Minimum GPA Required: " << gpa << '\n'
<< " | Minimum English Level Required: " << english_lvl << '\n'
<< " | Tuition Fees: " << tuition_fees << "$ / Year.\n"
<< desc << "\n\n";
}
void showInList(int i) const {
cout << "|[" << i + 1 << "]| Uni: " << name << " | Region: " << p_region
<< " | Degree: " << degree_lvl << " | Programme: " << programme
<< " | Tuition Fees: " << tuition_fees << "$.\n" << desc << "\n\n";
}
// Get Methods
double getTuitionFees() const { return tuition_fees; }
degree_level getDegreeLvl() const { return degree_lvl; }
english_level getEnglishLvl() const { return english_lvl; }
float getGPA() const { return gpa; }
bankAccount getBank() const { return uniBank; }
int getCounter() const { return counter; }
};
class receipt {
private:
string transactionType;
double amount;
double balance;
unsigned int accountNumber;
public:
receipt(const string& transactionType, double amount, double balance, unsigned int accountNumber)
: transactionType(transactionType), amount(amount), balance(balance), accountNumber(accountNumber) {}
void display() const {
cout << BOLD << GREEN << "Transaction Receipt\n"
<< "--------------------\n"
<< "Transaction Type: " << transactionType << "\n"
<< "Amount: $" << amount << "\n"
<< "Remaining Balance: $" << balance << "\n"
<< "Account Number: " << accountNumber << "\n"
<< "--------------------\n" << RESET;
}
~receipt() {
cout << BOLD << RED << "Take a screenshot for the reciept before it gets destroyed.\n\n" << RESET;
}
};
// Initial Value for the Static Variables
int bankAccount::counter = 0;
int university::counter = 0;
// Testing Data
university uni1("Oxford University", region::Europe, "The University of Oxford is a collegiate research university in Oxford, England. There is evidence of teaching as early as 1096, making it the oldest university in the English-speaking world and the world's second-oldest university in continuous operation.", study_programme::ComputerScience, degree_level::Undergraduate, english_level::B2, 50000, 3.9);
university uni2("Harvard University", region::America, "Established in 1636, Harvard is the oldest higher education institution in the United States, and is widely regarded in terms of its influence, reputation, and academic pedigree as a leading university in not just the US but also the world.", study_programme::ComputerScience, degree_level::Undergraduate, english_level::B2, 40000, 3.8);
university uni3("Cambridge University", region::Europe, "The University of Cambridge is one of the world's oldest universities and leading academic centres, and a self-governed community of scholars. Established in 1209, the University is rich in history.", study_programme::ComputerScience, degree_level::Undergraduate, english_level::B2, 30000, 3.7);
university uni4("Stanford University", region::America, "A private research university located in Stanford, California. Known for its entrepreneurial culture and proximity to Silicon Valley.", study_programme::Engineering, degree_level::Undergraduate, english_level::C1, 60000, 3.95);
university uni5("National University of Singapore", region::Asia, "A leading research university in Singapore. Offers a broad range of disciplines in engineering, science, business, and the arts and humanities.", study_programme::Business, degree_level::Postgraduate, english_level::B2, 45000, 3.8);
university uni6("Massachusetts Institute of Technology (MIT)", region::America, "A private research university focused on science, technology, engineering, and mathematics. Renowned for its innovation and entrepreneurship.", study_programme::ComputerScience, degree_level::Undergraduate, english_level::C2, 70000, 4.0);
university uni7("University of Tokyo", region::Asia, "A public research university located in Tokyo, Japan. Considered one of the most prestigious universities in Asia.", study_programme::Arts, degree_level::Undergraduate, english_level::B1, 35000, 3);
university uni8("University of Toronto", region::America, "A public research university in Toronto, Canada. Consistently ranked among the top universities worldwide.", study_programme::Media, degree_level::Undergraduate, english_level::B2, 42000, 3.8);
university uni9("École Polytechnique Fédérale de Lausanne (EPFL)", region::Europe, "A Swiss public research university in Lausanne, focused on science and technology. Renowned for its engineering and computer science programs.", study_programme::Engineering, degree_level::Postgraduate, english_level::C1, 55000, 3.9);
university uni10("The University of Melbourne", region::Asia, "A public research university in Melbourne, Australia. One of Australia's oldest universities and a member of the prestigious Group of Eight research universities.", study_programme::Business, degree_level::Undergraduate, english_level::B2, 38000, 3.7);
university uni11("University of Cape Town (UCT)", region::Africa, "A public research university in Cape Town, South Africa. The oldest university in South Africa and a renowned institution for research and teaching.", study_programme::Arts, degree_level::Undergraduate, english_level::B1, 25000, 3.6);
university uni12("Peking University", region::Asia, "A national research university in Beijing, China. Considered one of China's most prestigious universities, with a strong focus on humanities and social sciences.", study_programme::Law, degree_level::Postgraduate, english_level::C2, 40000, 3.9);
// Vectors To Store Data
vector<bankAccount> bank_accounts_data = {uni1.getBank(), uni2.getBank(), uni3.getBank(), uni4.getBank(), uni5.getBank(), uni6.getBank(), uni7.getBank(), uni8.getBank(), uni9.getBank(), uni10.getBank(), uni11.getBank(), uni12.getBank()};
vector<studyFinderAccount> user_accounts_data;
vector<university> universities_data = {uni1, uni2, uni3, uni4, uni5, uni6, uni7, uni8, uni9, uni10, uni11, uni12};
// Friend function to check whether the applicant is qualified for the university he chose
bool qualificationCheck(const studyFinderAccount& user, const university& org) {
if (user.gpa >= org.gpa && user.english_lvl >= org.english_lvl) {
return true;
}else{
return false;
}
}
// Comparison Functions
bool sortByHigherTuition(const university& a, const university& b){
return a.getTuitionFees() > b.getTuitionFees();
}
bool sortByLowerTuition(const university& a, const university& b){
return a.getTuitionFees() < b.getTuitionFees();
}
bool sortByHigherAcceptance(const university& a, const university& b){
return a > b;
}
bool sortByLowerAcceptance(const university& a, const university& b){
return a < b;
}
// Display Functions ========================================================
// Start Display
inline void startDisplay() {
displayHeader("OOP Project");
vector<string> options = {
"Open StudyFinder",
"Open BankingSystem",
"Exit"
};
displayOptions(options);
}
// Bank Display
inline void bankHomeDisplay() {
displayHeader("BankingSystem");
vector<string> options = {
"Log in to your bank account",
"Create a new bank account",
"Back"
};
displayOptions(options);
}
inline void bankLoginDisplay(unsigned int accountNumber, const string& pinCode, unsigned short msg) {
displayHeader("BankingSystem - Login");
cout << BOLD << CYAN << "|[1]| " << RESET << (accountNumber ? to_string(accountNumber) : "*** Account Number") << "\n"
<< BOLD << CYAN << "|[2]| " << RESET << (pinCode.empty() ? "Enter PIN Code" : pinCode) << "\n"
<< BOLD << CYAN << "|[3]| " << RESET << "Log in\n"
<< BOLD << CYAN << "|[0]| " << RESET << "Back\n\n";
vector<string> messages = {
"",
"Incorrect PIN code! Please try again.",
"Account does not exist! Please try again."
};
displayErrorMessage(msg, messages);
}
inline void bankRegisterDisplay(const string& accountName, const string& pinCode, unsigned short msg, unsigned int accountNumber) {
displayHeader("BankingSystem - Register");
cout << BOLD << CYAN << "|[1]| " << RESET << (accountName.empty() ? "Enter Account Name" : accountName) << "\n"
<< BOLD << CYAN << "|[2]| " << RESET << (pinCode.empty() ? "Enter PIN Code" : pinCode) << "\n"
<< BOLD << CYAN << "|[3]| " << RESET << "Create Account\n"
<< BOLD << CYAN << "|[0]| " << RESET << "Back\n\n";
vector<string> messages = {
"",
"Account already exists! Try a different name.",
"New bank account created! Your account number is " + to_string(accountNumber) + "."
};
displayErrorMessage(msg, messages);
}
inline void bankMainMenuDisplay(const string& accountName, double balance) {
displayHeader("BankingSystem - Main Menu");
cout << BOLD << YELLOW << "| " << accountName << " | Balance: $" << balance << " |\n\n" << RESET;
vector<string> options = {
"Deposit",
"Withdraw",
"Transfer",
"View Account Info",
"Change PIN Code",
"Sign Out"
};
displayOptions(options);
}
inline void bankDepositWithdrawDisplay(const string& accountName, double balance, const string& amount, bool type, unsigned short msg) {
displayHeader(type ? "BankingSystem - Deposit" : "BankingSystem - Withdraw");
cout << BOLD << YELLOW << "| " << accountName << " | Balance: $" << balance << " |\n\n" << RESET
<< BOLD << CYAN << "|[1]| " << RESET << (amount.empty() ? "Enter Amount" : "$" + amount) << "\n"
<< BOLD << CYAN << "|[2]| " << RESET << (type ? "Deposit" : "Withdraw") << "\n"
<< BOLD << CYAN << "|[0]| " << RESET << "Back\n\n";
vector<string> messages = type ? vector<string>{
"",
"Failed: Minimum deposit is $5.",
"Failed: Maximum deposit is $10,000.",
"Success: $" + amount + " deposited."
} : vector<string>{
"",
"Failed: Minimum withdrawal is $5.",
"Failed: Maximum withdrawal is $10,000.",
"Success: $" + amount + " withdrawn."
};
displayErrorMessage(msg, messages);
}
inline void bankTransferDisplay(const string& accountName, double balance, const string& amount, unsigned int accountNumber, unsigned short msg) {
displayHeader("BankingSystem - Transfer");
cout << BOLD << YELLOW << "| " << accountName << " | Balance: $" << balance << " |\n\n" << RESET
<< BOLD << CYAN << "|[1]| Amount: " << RESET << (amount.empty() ? "Enter Amount" : "$" + amount) << '\n'
<< BOLD << CYAN << "|[2]| To Account Number: " << RESET << (accountNumber == 0 ? "Enter Account Number" : to_string(accountNumber)) << '\n'
<< BOLD << CYAN << "|[3]| Transfer\n"
<< BOLD << CYAN << "|[0]| Back\n\n" << RESET;
vector<string> messages = {
"",
"Failed: Minimum transfer is $5.",
"Failed: Insufficient balance.",
"Failed: Account not found.",
"Success: $" + amount + " transferred to account " + to_string(accountNumber) + "."
};
displayErrorMessage(msg, messages);
}
inline void bankChangePINDisplay(const string& accountName, double balance, const string& c_pin, const string& n_pin, unsigned short msg) {
displayHeader("BankingSystem - Change PIN");
cout << BOLD << YELLOW << "| " << accountName << " | Balance: $" << balance << " |\n\n" << RESET
<< BOLD << CYAN << "|[1]| Current PIN: " << RESET << (c_pin.empty() ? "Enter Current PIN" : "*****") << "\n"
<< BOLD << CYAN << "|[2]| New PIN: " << RESET << (n_pin.empty() ? "Enter New PIN" : "*****") << "\n"
<< BOLD << CYAN << "|[3]| Confirm\n"
<< BOLD << CYAN << "|[0]| Back\n\n" << RESET;
vector<string> messages = {
"",
"Incorrect current PIN.",
"PIN changed successfully."
};
displayErrorMessage(msg, messages);
}
// StudyFinder Display
inline void studyFinderHomeDisplay() {
displayHeader("StudyFinder");
vector<string> options = {
"Log in",
"Create a new account",
"Back"
};
displayOptions(options);
}
inline void studyFinderLoginDisplay(const string& username, const string& password, unsigned short msg) {
displayHeader("StudyFinder - Login");
cout << BOLD << CYAN << "|[1]| " << RESET << (username.empty() ? "Enter Username" : username) << "\n"
<< BOLD << CYAN << "|[2]| " << RESET << (password.empty() ? "Enter Password" : password) << "\n"
<< BOLD << CYAN << "|[3]| Log in\n"
<< BOLD << CYAN << "|[0]| Back\n\n" << RESET;
vector<string> messages = {
"",
"Incorrect password! Please try again.",
"Account does not exist! Please try again."
};
displayErrorMessage(msg, messages);
}
inline void studyFinderRegisterDisplay(const string& username, const string& password, unsigned short msg) {
displayHeader("StudyFinder - Register");
cout << BOLD << CYAN << "|[1]| " << RESET << (username.empty() ? "Enter Username" : username) << "\n"
<< BOLD << CYAN << "|[2]| " << RESET << (password.empty() ? "Enter Password" : password) << "\n"
<< BOLD << CYAN << "|[3]| Create Account\n"
<< BOLD << CYAN << "|[0]| Back\n\n" << RESET;
vector<string> messages = {
"",
"Account already exists! Try a different username.",
"Account created successfully."
};
displayErrorMessage(msg, messages);
}
inline void studyFinderMainMenuDisplay(const string& username) {
displayHeader("StudyFinder - Main Menu");
cout << BOLD << YELLOW << "| Welcome, " << username << " |\n\n" << RESET;
vector<string> options = {
"Search for Study Opportunities",
"Update Student Profile",
"Account Security Settings",
"Sign Out"
};
displayOptions(options);
}
inline void studyFinderApplyDisplay(const string& username, university& selectedUni) {
displayHeader("StudyFinder");
cout << BOLD << YELLOW << "| Welcome, " << username << " |\n\n" << RESET
<< "=======================| Show All |=======================\n";
selectedUni.display();
cout << "\n"
<< BOLD << CYAN << "|[1]| Apply\n"
<< BOLD << CYAN << "|[0]| Back\n" << RESET;
}
inline void studyFinderSelectDisplay(const string& username, university& selectedUni) {
displayHeader("StudyFinder");
cout << BOLD << YELLOW << "| Welcome, " << username << " |\n\n" << RESET
<< "=======================| Show All |=======================\n";
selectedUni.display();
cout << "\n"
<< BOLD << CYAN << "|[1]| Apply\n"
<< BOLD << CYAN << "|[0]| Back\n" << RESET;
}
inline void studyFinderShowAllOptionsDisplay(const string& username, int counter) {
displayHeader("StudyFinder");
cout << BOLD << YELLOW << "| Welcome, " << username << " |\n\n"
<< "===========| Show All | ==== | Found: " << counter << " |===========|\n" << RESET;
vector<string> options = {
"Sort by higher tuition fees",
"Sort by lower tuition fees",
"Sort by higher acceptance chance",
"Sort by lower acceptance chance",
"Back"
};
displayOptions(options);
cout << "==================================================================\n\n";
}
inline void studentProfileSettingsDisplay(const string& username, const string& realname, region reg, gender gen, unsigned short age, degree_level degree_lvl, english_level english_lvl, float gpa) {
displayHeader("StudyFinder - Profile Settings");
cout << BOLD << YELLOW << "| Welcome, " << username << " |\n\n" << RESET
<< "| \"*\" indicates required fields |\n"
<< BOLD << CYAN << "|[1]| Real Name: " << RESET << realname << '\n'
<< BOLD << CYAN << "|[2]| Gender: " << RESET << gen << '\n'
<< BOLD << CYAN << "|[3]| Age: " << RESET << age << '\n'
<< BOLD << CYAN << "|[4]| Region: " << RESET << reg << '\n'
<< BOLD << CYAN << "|[5]| Degree Level*: " << RESET << degree_lvl << '\n'
<< BOLD << CYAN << "|[6]| GPA*: " << RESET << gpa << " (out of 4.0)\n"
<< BOLD << CYAN << "|[7]| English Level*: " << RESET << english_lvl << '\n'
<< BOLD << CYAN << "|[0]| Back\n" << RESET;
}
inline void accountSecuritySettingsDisplay(const string& username, unsigned short msg) {
displayHeader("StudyFinder - Account Security");
cout << BOLD << CYAN << "|[1]| Username: " << RESET << username << '\n'
<< BOLD << CYAN << "|[2]| Change Password\n"
<< BOLD << CYAN << "|[0]| Back\n\n" << RESET;
vector<string> messages = {
"",
"Incorrect current password",
"Password changed successfully"
};
displayErrorMessage(msg, messages);
}
// Main Functions Definitions ========================================================
// Bank
void bankLogin(unsigned int, string, unsigned short);
void bankRegister(string, string, unsigned short, unsigned int);
void bank();
void bankMainMenu(bankAccount&, bool);
void bankDeposit(bankAccount&, string, double, unsigned short);
void bankWithdraw(bankAccount&, string, double, unsigned short);
void bankTransfer(bankAccount&, string, double, unsigned int, unsigned short);
// StudyFinder
void studyFinderLogin(string, string, unsigned short);
void studyFinderRegister(string, string, unsigned short);
void studyFinderProfileSettings(studyFinderAccount&);
void studyFinderAccountSecuritySettings(studyFinderAccount&, unsigned short);
void studyFinderSelect(studyFinderAccount&, university&);
void studyFinderShowResults(studyFinderAccount&);
void studyFinder();
void studyFinderMainMenu(studyFinderAccount&);
// Start
void start();
// Starting Point
int main(){
start();
return 0;
}
// Main Functions ========================================================
// Bank
void bankLogin(unsigned int accountNumber = 0, string pinCode = "*** PIN Code...", unsigned short msg = 0){
bankLoginDisplay(accountNumber, pinCode, msg);
switch(choose(0, 3)){
case 1:
cout << "|[USER-INPUT]| Enter your account number: ";
cin >> accountNumber;
bankLogin(accountNumber, pinCode, 0);
break;
case 2:
cout << "|[USER-INPUT]| Enter your PIN code: ";
cin >> pinCode;
bankLogin(accountNumber, pinCode, 0);
break;
case 3:
{
for (int i = 0; i < bank_accounts_data.size(); ++i){
if (accountNumber == bank_accounts_data[i].getNumber()){
if (pinCode == bank_accounts_data[i].getPinCode()){
// SUCCESSFULLY LOGGED IN
bankMainMenu(bank_accounts_data[i], false);
return;
}else{
// Wrong PIN Code
bankLogin(accountNumber, pinCode, 1);
return;
}
}
}
bankLogin(accountNumber, pinCode, 2);
}
break;
case 0: bank(); return;
}
}
void bankRegister(string accountName = "*** Account Name...", string pinCode = "*** PIN Code...", unsigned short msg = 0, unsigned int accountNumber = 0){
bankRegisterDisplay(accountName, pinCode, msg, accountNumber);
switch(choose(0, 3)){
case 1:
cout << "|[USER-INPUT]| Create your account name: ";
cin >> accountName;
bankRegister(accountName, pinCode, msg);
break;
case 2:
cout << "|[USER-INPUT]| Create your PIN code: ";
cin >> pinCode;
bankRegister(accountName, pinCode, msg);
break;
case 3:
{
for (int i = 0; i < bank_accounts_data.size(); ++i){
if (accountName == bank_accounts_data[i].getName()){
bankRegister(accountName, pinCode, 1);
return;
}
}
bankAccount newBankAccount(accountName, pinCode);
bank_accounts_data.emplace_back(newBankAccount);
bankRegister("*** Account Name...", "*** PIN Code...", 2, newBankAccount.getNumber());
}
break;
case 0: bank(); return;
}
}
void bankDeposit(bankAccount& account, string amount = "*** Amount to deposit...", double cash = 0, unsigned short msg = 0){
bankDepositWithdrawDisplay(account.getName(), account.getBalance(), amount, true, msg);
if (msg == 3){
receipt deposit_receipt("Deposit", cash, account.getBalance(), account.getNumber());
deposit_receipt.display();
}
switch(choose(0, 2)){
case 1:
cout << "|[USER-INPUT]| Enter amount to deposit: ";
cin >> cash;
amount = to_string(cash) + '$';
bankDeposit(account, amount, cash);
break;
case 2:
bankDeposit(account, amount, cash, account.deposit(cash));
break;
case 0: bankMainMenu(account, false); return;
}
}
void bankTransfer(bankAccount& senderAccount, string amount = "*** Amount to transfer...", double cash = 0, unsigned int receiverAccountNumber = 0, unsigned short msg = 0) {
bankTransferDisplay(senderAccount.getName(), senderAccount.getBalance(), amount, receiverAccountNumber, msg);
if (msg == 4){
receipt deposit_receipt("Transfer", cash, senderAccount.getBalance(), senderAccount.getNumber());
deposit_receipt.display();
}
switch (choose(0, 3)) {
case 1:
cout << "|[USER-INPUT]| Enter amount to transfer: ";
cin >> cash;
amount = to_string(cash) + '$';
bankTransfer(senderAccount, amount, cash, receiverAccountNumber, msg);
break;
case 2:
cout << "|[USER-INPUT]| Enter account number: ";
cin >> receiverAccountNumber;
bankTransfer(senderAccount, amount, cash, receiverAccountNumber, msg);
break;
case 3:
for (auto& receiverAccount : bank_accounts_data) {
if (receiverAccount.getNumber() == receiverAccountNumber) {
bankTransfer(senderAccount, amount, cash, receiverAccountNumber, senderAccount.transfer(cash, receiverAccount));
return;
}
}
bankTransfer(senderAccount, amount, cash, receiverAccountNumber, 3);
break;
case 0: bankMainMenu(senderAccount, false); return;
}
}
void bankWithdraw(bankAccount& account, string amount = "*** Amount to withdraw...", double cash = 0, unsigned short msg = 0){
bankDepositWithdrawDisplay(account.getName(), account.getBalance(), amount, false, msg);
if (msg == 3){
receipt deposit_receipt("Withdraw", cash, account.getBalance(), account.getNumber());
deposit_receipt.display();
}
switch(choose(0, 2)){
case 1:
cout << "|[USER-INPUT]| Enter amount to withdraw: ";
cin >> cash;
amount = to_string(cash) + '$';
bankWithdraw(account, amount, cash);
break;
case 2:
bankWithdraw(account, amount, cash, account.withdraw(cash));
break;
case 0: bankMainMenu(account, false); return;
}
}
void bankChangePIN(bankAccount& account, string c_pin = "*** Current PIN Code...", string n_pin = "*** New PIN Code...", unsigned short msg = 0){
bankChangePINDisplay(account.getName(), account.getBalance(), c_pin, n_pin, msg);
switch(choose(0, 3)){
case 1:
cout << "|[USER-INPUT]| Enter your current PIN code: ";
cin >> c_pin;
bankChangePIN(account, c_pin, n_pin, msg);
break;
case 2:
cout << "|[USER-INPUT]| Enter your new PIN code: ";
cin >> n_pin;
bankChangePIN(account, c_pin, n_pin, msg);
break;
case 3:
if (c_pin != account.getPinCode()){
bankChangePIN(account, c_pin, n_pin, 1);
}else{
account.setPinCode(n_pin);
bankChangePIN(account, c_pin, n_pin, 2);
}
break;
case 0: bankMainMenu(account, false); return;
}
}
void bank(){
bankHomeDisplay();
switch(choose(0, 2)){
case 1: bankLogin(); break;
case 2: bankRegister(); break;
case 0: start(); return;
}
}
void bankMainMenu(bankAccount& account, bool showInfo = false){
bankMainMenuDisplay(account.getName(), account.getBalance());
if (showInfo) account.display();
switch(choose(0, 5)){
case 1: bankDeposit(account); break;
case 2: bankWithdraw(account); break;
case 3: bankTransfer(account); break;
case 4: bankMainMenu(account, true); break;
case 5: bankChangePIN(account); break;
case 0: bank(); return;
}
}
// StudyFinder
void studyFinderLogin(string username = "*** Username...", string password = "*** Password...", unsigned short msg = 0){
studyFinderLoginDisplay(username, password, msg);
switch(choose(0, 3)){
case 1:
cout << "|[USER-INPUT]| Enter your username: ";
cin >> username;
studyFinderLogin(username, password, msg);
break;
case 2:
cout << "|[USER-INPUT]| Enter your password: ";
cin >> password;
studyFinderLogin(username, password, msg);
break;
case 3:
{
// Mahrous Task Here ***
// Make your code here to search for the desired data
// For now I will use vectors as database so I can test the project --Ahmed Yasser Eissa
for (int i = 0; i < user_accounts_data.size(); ++i){
if (username == user_accounts_data[i].getUsername()){
if (password == user_accounts_data[i].getPassword()){
// Successfully logged in
studyFinderMainMenu(user_accounts_data[i]);
return;
}else{
// Password doesn't match the account
studyFinderLogin(username, password, 1);
return;
}
}
}
// Username doesn't match any account
studyFinderLogin(username, password, 2);
}
break;
case 0: studyFinder(); return;
}
}
void studyFinderRegister(string username = "*** Username...", string password = "*** Password...", unsigned short msg = 0){
studyFinderRegisterDisplay(username, password, msg);
switch(choose(0, 4)){
case 1:
cout << "|[USER-INPUT]| Create your username: ";
cin >> username;
studyFinderRegister(username, password, msg);
break;
case 2:
cout << "|[USER-INPUT]| Create your password: ";
cin >> password;
studyFinderRegister(username, password, msg);
break;
case 3:
{
for (int i = 0; i < user_accounts_data.size(); ++i){
if (username == user_accounts_data[i].getUsername()){
// Found an existed account with same username
studyFinderRegister(username, password, 1);
return;
}
}
// Creating a new account
studyFinderAccount newUserAccount(username, password);
user_accounts_data.emplace_back(newUserAccount);
studyFinderRegister(username, password, 2);
}
break;
case 0: studyFinder(); return;
}
}
void studyFinderProfileSettings(studyFinderAccount& account){
studentProfileSettingsDisplay(account.getUsername(), account.getRealName(), account.getRegion(), account.getGender(), account.getAge(), account.getDegreeLvl(), account.getEnglishLvl(), account.getGPA());
switch(choose(0, 7)){
case 1:
{
string input;
cout << "|[USER-INPUT]| Enter your Real Name: ";
cin >> input;
account.setRealName(input);
studyFinderProfileSettings(account);
}
break;
case 2:
{
gender input = inputGender();
cout << "|[USER-INPUT]| Enter your Gender: ";
account.setGender(input);
studyFinderProfileSettings(account);
}
break;
case 3:
{
unsigned short input;
cout << "|[USER-INPUT]| Enter your Age: ";
cin >> input;
account.setAge(input);
studyFinderProfileSettings(account);
}
break;