-
Notifications
You must be signed in to change notification settings - Fork 2
/
BankApplication.cpp
152 lines (143 loc) · 5.71 KB
/
BankApplication.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
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: https://pvs-studio.com
//Implementation of BankApplication Class
#include "BankSystem_Classes.h"
BankApplication::BankApplication()
{
}
bool BankApplication::addClient()
{
string name,address,phone;
int type{0};
BankAccount *account = nullptr;
cout<<"Please enter name: ";cin.ignore();getline(cin,name);
while (!regex_match(name, regex("([_a-zA-Z]*)")))
{
cout << "Invalid User Name!, Try Again\n:";
getline(cin,name);
}
cout<<"Please enter address: ";getline(cin,address);
cout<<"Please enter phone number: ";cin>>phone;
while(!regex_match(phone, regex("(01)(1|2|5|0)([0-9]+)")) || (phone.size() != 11 && phone.size() != 10) )
{
cout<<"Please enter a correct phone number: ";
cin >> phone;
}
cout<<"What Type of Account Do You Like? (1) Basic (2) Saving - Type 1 or 2: "; cin>>type;
if(type==1){
double initialBalance = 0;
cout<<"Please enter the starting balance: ";cin>>initialBalance;
if(initialBalance<=0){
cout<<"Sorry,Bad input\n";
return false;
}
account = new BankAccount(initialBalance);
Client client(name,address,phone,account);
clients.push_back(client);
}else if(type==2){
SavingsBankAccount temp(0);
double initialBalance= 0;
cout<<"Please enter the starting balance of your savings account: ";
cin>>initialBalance;
temp.setfci(temp.getfci()-1);
if(initialBalance<temp.getMinimumBalance()){
cout << "The Minimum price to create an account is " << temp.getMinimumBalance() <<endl;
}else{
account = new SavingsBankAccount(initialBalance);
Client client(name,address,phone,account);
clients.push_back(client);
}
}
//Have to change constructor of client to take Bank Account Pointer to allow for polymorphism
}
void BankApplication::displayClientsAndAccounts()
{
for(auto i : clients)
cout << i << endl;
}
void BankApplication::run() {
start:;
int choose;
cout << "Welcome to FCAI Banking Application\n"
"1. Create a New Account\n"
"2. List Clients and Accounts\n"
"3. Withdraw Money\n"
"4. Deposit Money\n"
"5. Exit\n"
"Please Enter Choice : ";
cin >> choose;
if ( choose == 1 ){
this->addClient();
}
else if (choose == 2){
this->displayClientsAndAccounts();
}
else if (choose == 3){
string accountID;
bool founded= false;
cin.ignore();
cout << "Please enter account ID: ";getline(cin,accountID);
while (accountID.length()>20){
cout<<"Input too long,Please try again"<<endl;
cout << "Please enter account ID: ";getline(cin,accountID);
}
for(auto& client : clients){
//To - Do : Assuming best case scenario that the account exist.... but what if account does not exist? Add that else condition
if(client.getBankAccount()->getAccountID()==accountID){
cout<<"Account ID: "<<accountID<<endl;
cout<<"Account Type: "<<client.getBankAccount()->getAccounttype()<<endl;
cout<<"Balance: "<<client.getBankAccount()->getBalance()<<endl;
double amount;
cout<<"Please enter the amount to withdraw: ";cin>>amount;
client.getBankAccount()->withdraw(amount);
cout<<"Thank You."<<endl;
cout<<"Account ID: "<<accountID<<endl;
cout<<"New balance: "<<client.getBankAccount()->getBalance()<<endl;
founded= true;
break; // End the search for clients
}
// TO-DO: Add else condition "done"
}
if(!founded){
cout<<"Account not founded,Please try again"<<endl;
goto start;
}
}
else if ( choose == 4 ) { //Same as withdraw but only difference -> call deposit.
string accountID;
cin.ignore();
cout << "Please enter account ID: ";getline(cin,accountID);
while (accountID.length()>20){
cout<<"Input too long,Please try again"<<endl;
cout << "Please enter account ID: ";getline(cin,accountID);
}
bool founded= false;
for(auto& client : clients){
//To - Do : Assuming best case scenario that the account exist.... but what if account does not exist? Add that else condition
//Fix account type using base constructor
//Fix taking long string input using get line function
if(client.getBankAccount()->getAccountID()==accountID){
cout<<"Account ID: "<<accountID<<endl;
cout<<"Account Type: "<<client.getBankAccount()->getAccounttype()<<endl;
cout<<"Balance: "<<client.getBankAccount()->getBalance()<<endl;
double amount;
cout<<"Please enter the amount to deposit: ";cin>>amount;
client.getBankAccount()->deposit(amount);
cout<<"Thank You."<<endl;
cout<<"Account ID: "<<accountID<<endl;
cout<<"New balance: "<<client.getBankAccount()->getBalance()<<endl;
founded= true;
break; // End the search for clients
}
// TO-DO: Add else condition "done"
}
if(!founded){
cout<<"Account not founded,Please try again"<<endl;
goto start;
}
}else if(choose==5){
cout<<"Thank You."<<endl;
exit(0);
}else
throw invalid_argument("Bad Input !!");
}