-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
323 lines (286 loc) · 9.7 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
#include "PersonalDetails.h"
#include "Bank.h"
#include "simple.h"
#include "compound.h"
#include "account.h"
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// FUNCTION DEFINITIONS
// vector array to store everyone's personal details
// memory allocation for object vector from stack
vector<PersonalDetails> personalDetailsVector;
// vector array to store everyone's user accounts
vector<account> userAccountsVector;
// vector array to store bank information
// is a bank vector necessary? because we are storing user accounts in the vector userAccounts vector
// vector<Bank> bankVector;
// main UI when user first logs into bank system
void mainscreen();
// create user functionality. see function for details.
void createUser();
void Login();
void resetPassword();
void viewAccount(int account_index);
// MAIN FUNCTION
int main()
{
// initial log in UI function called.
mainscreen();
// print out users for debugging purposes. it works.
for (int i = 0; i < personalDetailsVector.size(); i++)
{
cout << personalDetailsVector[i].getFullName() << endl;
}
return 0;
}
// mainscreen function
void mainscreen()
{
// exit is false so that the main screen loop runs at least once.
bool exit = false;
// while loop for logic. The loop will exit when the user performs some
// action like creating an user.
while (exit == false)
{
// new variable option to allow user to performance an action
int option;
cout << "Hello there! What would you like to do?\nEnter the option:" << endl;
cout << "1.) Create User" << endl;
cout << "2.) Login" << endl;
cout << "3.) Reset Password" << endl;
cout << "4.) Exit" << endl;
cin >> option;
// a switch statement for the menu logic
switch (option)
{
// case to allow user to enter their personal details
case 1:
createUser();
exit = true;
break;
// case which allows for user to exit
case 2:
Login();
exit = true;
break;
// reset password functionality
case 3:
resetPassword();
exit = true;
break;
// exit the bank program
case 4:
exit = true;
cout << "Bye!" << endl;
break;
// case where input is invalid.
default:
cout << "Invalid try again!" << endl;
break;
}
}
};
// function to create a user
void createUser()
{
// this is the list of questions that he user must be asked.
string questionaire[11] = {
"Your full name:",
"Your phone number:",
"Your email:",
"Your secret question (this will be used to reset your password):",
"Your secret answer:",
"Your age:",
"Your annual income (this will determine if you can take out loans or not):",
"Your username:",
"Your password:",
"Confirm password:",
"Made a mistake?(y/n):",
};
// this will store the questionaire answer and pass them to the newUser
// variable to create a new user.
string questionaire_answers[11] = {};
// this will repeat the user details loop
questionaire_answers[10] = "n";
// this loop will ask the user their details. will loop until user
// the user doesn't make a mistake in their details. using a do-while
// loop so that the loop runs at least once.
do
{
for (int i = 0; i < 11; i++)
{
// # IF WE GET MORE TIME: add input sanitation
// # TODO: check if username is taken
// I think the way we are reading the string is
// causing issues with the testing text file
cout << questionaire[i] << endl;
cin.ignore(1);
getline(cin, questionaire_answers[i]);
}
} while (questionaire_answers[10] == "y");
// if password and confirm password don't match, ask the user to enter
// to enter them again.
while (questionaire_answers[8] != questionaire_answers[9])
{
cout << "Your passwords don't match. Please enter them again: " << endl;
cin.ignore(1, '\n');
getline(cin, questionaire_answers[8]);
cout << "Confirm password: " << endl;
cin.ignore(1, '\n');
getline(cin, questionaire_answers[9]);
}
// A message to the user saying user is saved.
cout << "User details saved!" << endl;
// temporary variable to store new user information.
PersonalDetails newUser(questionaire_answers);
// adding the newUser to the vector array
personalDetailsVector.push_back(newUser);
// pass account details to account
account newAccount(newUser);
// push into account array
userAccountsVector.push_back(newAccount);
// return to the main screen
mainscreen();
};
// function to view the person's account
void viewAccount(int account_index)
{
bool exit = false;
while (exit == false)
{
int option;
cout << "Your Balance:" << userAccountsVector[account_index].get_balance() << endl;
cout << "Your credit score:" << userAccountsVector[account_index].get_credit_score() << endl;
cout << "Your interest rate on your loan:" << userAccountsVector[account_index].get_interest_rate() << endl;
cout << "Your loan balance:" << userAccountsVector[account_index].get_current_loan() << endl;
cout << "Your loan limit: " << userAccountsVector[account_index].get_loan_limit();
cout << "What would you like to do?" << endl;
cout << "1.) Deposit " << endl;
cout << "2.) Withdraw " << endl;
cout << "3.) Pay installment " << endl;
cout << "4.) New loan " << endl;
cout << "5.) Transfer to another account " << endl;
cout << "6.) Exit " << endl;
cin >> option;
switch (option)
{
case 1:
double deposit;
cout << "Please enter deposit amount: " << endl;
cin >> deposit;
userAccountsVector[account_index].deposit(deposit);
break;
case 2:
double withdraw;
cout << "Please enter withdrawal amount: " << endl;
cin >> withdraw;
userAccountsVector[account_index].withdraw(withdraw);
case 3:
double pay;
cout << "Please enter how much you are paying off: " << endl;
cin >> pay;
userAccountsVector[account_index].pay_loan(pay);
case 4:
double loan;
cout << "Please enter how much you would like to loan: " << endl;
while (loan + userAccountsVector[account_index].get_current_loan() > personalDetailsVector[account_index].getAnnualIncome())
{
cout << "Sorry that exceeds your loan limit!\nPlease enter how much you would like to loan: " << endl;
}
}
}
}
// function to reset user password
void resetPassword()
{
bool exit = false;
string email;
while (exit == false)
{
cout << "Please enter your email:" << endl;
cin >> email;
for (int i = 0; i < personalDetailsVector.size(); i++)
{
if (email == personalDetailsVector[i].getEmail())
{
string answer;
cout << personalDetailsVector[i].getSecretQuestion() << endl;
cin >> answer;
if (answer == personalDetailsVector[i].getSecretAnswer())
{
string new_password, confirm_password;
cout << "Answered correctly! Please enter your new password:" << endl;
while (new_password != confirm_password)
{
cout << "Please enter your new password:" << endl;
cin >> new_password;
cout << "Confirm password: " << endl;
cin >> confirm_password;
if (new_password != confirm_password)
{
cout << "Please try again!" << endl;
}
}
cout << "Successfully set your new password: " << endl;
mainscreen();
exit = true;
}
}
else
{
cout << "Email does not exist! Try again!" << endl;
}
}
}
}
// function to login into account
void Login()
{
bool exit = false;
string email;
string password;
while (exit == false)
{
cout << "Please enter your email:" << endl;
cin >> email;
cout << "Please enter your password:" << endl;
cin >> password;
for (int i = 0; i < personalDetailsVector.size(); i++)
{
if (email == personalDetailsVector[i].getEmail() && password == personalDetailsVector[i].getPassword())
{
cout << "Sign in successful!" << endl;
viewAccount(i);
exit = true;
}
else
{
cout << "Password is incorrect!" << endl;
}
}
int option;
cout << "Email is incorrect!" << endl;
cout << "1.) Try again " << endl
<< "2.) Create user " << endl
<< "3.) Exit" << endl;
cin >> option;
switch (option)
{
case 1:
continue;
break;
case 2:
createUser();
exit = true;
break;
case 3:
exit = true;
break;
default:
cout << "Please try again! Type 1, 2 or 3 only" << endl;
break;
}
}
}