-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
389 lines (298 loc) · 9.07 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
#include <iostream>
#include <vector>
#include <string>
#include "bankAccount.cpp"
#include "savingAccount.cpp"
#include "highInterest.cpp"
#include "checkingAccount.cpp"
#include "servCharegCheck.cpp"
#include "noService.cpp"
#include "highChecking.cpp"
#include "cetrificate.cpp"
using namespace std;
namespace typeOfAccount
{
string saving="saving";
string highInterest="highInterest";
string checkingAccount="checkingAccount";
string servCharegCheck="servCharegCheck";
string noService="noService";
string highCheking="highCheking";
string certificate="certificate";
};
//make struct to hold all data for the system
struct Info
{
int accountNumCounter;
vector<savingAccount> saving_Accounts;
vector<highInterest> high_intrest;
vector<checkingAccount> checking_Account;
vector<servCharegCheck> serv_chareg;
vector<noService> no_service;
vector<highCheking> high_cheking;
vector<certificate> certifi_cate;
};
Info info; //Here all structures stored
//Here we Declare all functions
void ToCreate();
void creatNewAccount(string);
template <class accountType>
bool searchAccount(vector<accountType>, int &);
void editAccount();
void deleteAcount(string, int);
void printAll();
int main()
{
int choise = 0;
info.accountNumCounter = 1;
while (choise != 3)
{
cout << "\n\n\nWelcome to the bank system, please choose one of the following: ";
cout << "\n1.Create new Account "
<< "\n2.Edit an Account "
<< "\n3.Exit " << endl
<< "Enter a value:";
cin >> choise;
switch (choise)
{
case 1:
ToCreate();
break;
case 2:
editAccount();
break;
case 3:
break;
default:
cout << "\nWrong entry, try again please" << endl
<< endl;
}
}
return 0;
}
//This will create account and fill it with data
void ToCreate()
{
int dis;
while (dis != 8)
{
cout << "\nwhat type of account you want to create? "
<< "\n1.Saving account" << endl
<< "\n2.High interst account" << endl
<< "\n3.checking account " << endl
<< "\n4.service charge checking " << endl
<< "\n5.No service charge checking " << endl
<< "\n6.High checking account " << endl
<< "\n7.certificate of deposit " << endl
<< "\n8. Back to the main menu " << endl
<<endl<<"Enter a value:";
cin >> dis;
switch (dis)
{
case 1:
creatNewAccount(typeOfAccount::saving);
return;break;
case 2:
creatNewAccount(typeOfAccount::highInterest);
return;break;
case 3:
creatNewAccount(typeOfAccount::checkingAccount);
return;break;
case 4:
creatNewAccount(typeOfAccount::servCharegCheck);
return;break;
case 5:
creatNewAccount(typeOfAccount::noService);
return;break;
case 6:
creatNewAccount(typeOfAccount::highCheking);
return;break;
case 7:
creatNewAccount(typeOfAccount::certificate);
return;break;
case 8:
return;break;
default:
cout << "\nWrong entry, please try again";
break;
}
}
}
void creatNewAccount(string type) //Called from ToCreate()
{
string newName;
cin.ignore();
cout << "\nEnter name:";
getline(cin, newName);
double balance;
cout << "\nEnter balance:";
cin >> balance;
bankAccount *ptrBank = NULL;
if (typeOfAccount::saving == type)
{
//create new instance of class and store it in its vector
savingAccount *ptr = new savingAccount(newName, balance, info.accountNumCounter);
info.saving_Accounts.push_back(*ptr);
ptrBank=ptr;
ptr = NULL;
}
else if (typeOfAccount::highInterest == type)
{
// create new instance of class and store it in its vector
highInterest *ptr = new highInterest(newName, balance, info.accountNumCounter);
info.high_intrest.push_back(*ptr);
ptrBank=ptr;
ptr = NULL;
}
else if (typeOfAccount::checkingAccount == type)
{
// create new instance of class and store it in its vector
checkingAccount *ptr = new checkingAccount(newName, balance, info.accountNumCounter);
info.checking_Account.push_back(*ptr);
ptrBank=ptr;
ptr = NULL;
}
else if (typeOfAccount::servCharegCheck == type)
{
// create new instance of class and store it in its vector
servCharegCheck *ptr = new servCharegCheck(newName, balance, info.accountNumCounter);
info.serv_chareg.push_back(*ptr);
ptrBank=ptr;
ptr = NULL;
}
else if (typeOfAccount::noService == type)
{
// check so the minmun is 2000
if(balance<2000){cout<<endl<<endl<<"minmum balance fo this type is 2000 ";return;}
noService *ptr = new noService(newName, balance, info.accountNumCounter);
info.no_service.push_back(*ptr);
ptrBank=ptr;
ptr = NULL;
}
else if (typeOfAccount::highCheking == type)
{
// check so the minmun is 5000
if(balance<5000){cout<<endl<<endl<<"minmum balance fo this type is 5000 ";return;}
else{
highCheking *ptr = new highCheking(newName, balance, info.accountNumCounter);
info.high_cheking.push_back(*ptr);
ptrBank=ptr;
ptr = NULL;}
}
else if (typeOfAccount::certificate == type)
{
certificate *ptr = new certificate(newName, balance, info.accountNumCounter);
info.certifi_cate.push_back(*ptr);
ptrBank=ptr;
ptr = NULL;
}
else
{
cout << "Wrong entry " << endl;
return;
}
ptrBank->displayInfo();
info.accountNumCounter++; //Increase after creation
}
void editAccount()
{
int accNUmb;
cout << "What is the account number? ";
cin >> accNUmb; //To hold a number to look for, it found then this will hold the order in the vector
bool found = false;
bankAccount *ptr = NULL; //After searching, if the account found this will point to it
// string accountType;//used as parameter for delete function, to indicate the type of the account
if (searchAccount<savingAccount>(info.saving_Accounts, accNUmb))
{
ptr = &info.saving_Accounts[accNUmb];
cout << endl
<< "The account is ready, ";
ptr->editMenu();
found = true;
}
else if (searchAccount<highInterest>(info.high_intrest, accNUmb))
{
ptr = &info.high_intrest[accNUmb];
cout << endl
<< "The account is ready, ";
ptr->editMenu();
found = true;
}
else if (searchAccount<checkingAccount>(info.checking_Account, accNUmb))
{
ptr = &info.checking_Account[accNUmb];
cout << endl
<< "The account is ready, ";
ptr->editMenu();
found = true;
}
else if (searchAccount<servCharegCheck>(info.serv_chareg, accNUmb))
{
ptr = &info.serv_chareg[accNUmb];
cout << endl
<< "The account is ready, "<<endl<<endl;
ptr->editMenu();
found = true;
}
else if (searchAccount<noService>(info.no_service, accNUmb))
{
ptr = &info.no_service[accNUmb];
cout << endl
<< "The account is ready, "<<endl<<endl;
ptr->editMenu();
found = true;
}
else if (searchAccount<highCheking>(info.high_cheking, accNUmb))
{
ptr = &info.high_cheking[accNUmb];
cout << endl
<< "The account is ready, "<<endl<<endl;
ptr->editMenu();
found = true;
}
else if (searchAccount<certificate>(info.certifi_cate, accNUmb))
{
ptr = &info.certifi_cate[accNUmb];
cout << endl
<< "The account is ready, "<<endl<<endl;
ptr->editMenu();
found = true;
}
else if (!found)
{
cout << "\nThe account was not found ";
return;
}
return;
}
template <class accountType>
bool searchAccount(vector<accountType> accounts, int &accNUmb)
{
for (int i = 0; i < accounts.size(); i++)
{
if (accounts[i].getAccountNum() == accNUmb)
{
accNUmb = i;
return true;
}
}
return false;
}
void deleteAcount(string type, int index) //Delete an account,pass type so the function choose proper container,
{
if (type == "saving")
{
vector<savingAccount>::iterator it = info.saving_Accounts.begin();
info.saving_Accounts.erase(it + index);
cout << "Account Deleted" << endl
<< endl
<< endl;
}
}
void printAll()
{
for (int i = 0; i < info.saving_Accounts.size(); i++)
{
info.saving_Accounts[i].displayInfo();
}
}