-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAdmin.cpp
More file actions
212 lines (170 loc) · 4.31 KB
/
Copy pathAdmin.cpp
File metadata and controls
212 lines (170 loc) · 4.31 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
/*
* Admin.cpp
*
* Created on: Feb 1, 2014
* Author: nzayatz14
*/
#include "Admin.h"
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;
Admin::Admin() {
// TODO Auto-generated constructor stub
userName = "admin";
}
Admin::~Admin() {
// TODO Auto-generated destructor stub
}
void Admin::viewBank()
{
bank.printBank();
}
void Admin::viewAccounts()
{
cout<<"\nTotal number of accounts: "<<bank.getTotalAccounts()<<endl<<endl;
}
void Admin::viewAccountInDetail(){
// ask for the account number of the account that the user wishes to view
//if it is a valid account number, open<accountNumber.txt> read in all of
//the information and print it all. If its not print error and call printOptions
string user;
cout<<"Enter User Name: ";
cin>>user;
ExternalAccount ext;
bank.find(user, ext);
Client c;
Client *cPtr = &c;
InternalAccount t[2];
ext.getAccountHolder(cPtr);
cout<<endl<<c.getUserName()<<endl;
cout<<ext.getPassword()<<endl;
cout<<"Account Number: "<<ext.getAccountNumber()<<endl<<endl;
c.displayPersonalInformation();
cout<<endl;
ext.getInternalAccounts(t[0],t[1]);
t[0].displayInternalAccount();
cout<<endl;
t[1].displayInternalAccount();
cout<<endl;
}
void Admin::createAccount(){
//ask for general information
//create client object from entered info
//call bank.create ExternalAccount(client,password) function for bank class
Client clie;
string firstName;
string lastName;
string b;
char g;
string p;
string a;
string e;
string un;
string pass;
cout<<"Please enter first name of client."<< endl;
cin>>firstName;
cout<<"Please enter last name of client."<< endl;
cin>>lastName;
string n = firstName + " "+lastName;
cout<<"Please enter birthday of client."<< endl;
cin>>b;
cout<<"Please enter gender of client."<< endl;
cin>>g;
cout<<"Please enter in phone number of client"<< endl;
cin>>p;
getline(cin, a);
cout<<"Please enter in address of client:\n";
getline(cin, a);
cout<<"Please enter in email of client"<< endl;
cin>>e;
cout<<"Please enter in username of client"<< endl;
cin>>un;
cout<<"Please enter in a password"<< endl;
cin>>pass;
clie.setPerson(n,b,g,p,a,e,un);
bank.createExternalAccount(clie, pass);
}
void Admin::changePassword()
{
//ask for the userName of the account (check to make sure it exists and is the //correct account)
//ask for new password and re-entry
//if both entries match, find the externalAccount in the bank and set password in
//the temporary account to the new password
//set the externalAccount in the Bank equal to the temporary
//call printOptions()
ExternalAccount temp;
temp.setAccountNumber(-1);
string un;
string pass;
string pass2;
cout<<"Please enter the username of the account that you wish to change the password for:" << endl;
cin>>un;
bank.find(un, temp);
if(temp.getAccountNumber()!=-1){
cout<<"Please enter the new password of the account:" << endl;
cin>>pass;
cout<<"Please enter the password again:" << endl;
cin>>pass2;
if(pass.compare(pass2)==0){
temp.setPassword(pass);
bank.updateAccount(un, temp);
}
}
}
void Admin::deleteAccount(){
string un;
cout<<"Please enter the user name of the account you wish to delete:" << endl;
cin>>un;
bank.deleteExternalAccount(un);
}
void Admin::printOptions()
{
//print and number the capabilities of the administrator (create an account, delete
//an account, view a specific account, or change the password to an account)
//ask the option which the user wants to do (by number) and call the respective
//function
int n = -1;
do{
cout<<"Here you can do: \n1. View bank \n2. View the number of accounts \n3. View an account in detail \n4. Create an account \n5. Delete an account \n6. Change password of account \n0. Logout"<<
"\nEnter the number you wish to choose: ";
try{
cin>>n;
if(!cin)
throw 1;
}
catch(int a){
n=-1;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
}
switch(n){
case 1:
viewBank();
break;
case 2:
viewAccounts();
break;
case 3:
viewAccountInDetail();
break;
case 4:
createAccount();
break;
case 5:
deleteAccount();
break;
case 6:
changePassword();
break;
case 0:
break;
default:
cout<<"Please enter a valid number."<<endl;
}
}while (n!=0);
logout();
}
void Admin::logout(){
bank.logout();
}