-
Notifications
You must be signed in to change notification settings - Fork 25
/
project.cpp
316 lines (238 loc) · 5.59 KB
/
project.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
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "Data.h"
#include "Property.h"
#include <list>
using std::cout;
using std:: cin;
using std::endl;
using std::ofstream;
void addProperty(std::list<Data> &l)
{
Data datos;
string agentid,contact,size,roomtype,location,sellingprice;
cout<<"welcome to the propperty adding menu"<<endl;
cout<<"Please insert your Agent ID:"<<endl;
cin >> agentid;
datos.setAgentId(agentid);
cout<<"please insert your Contact:"<<endl;
cin >> contact;
datos.setContact(contact);
cout<<"please insert your Property Size:"<<endl;
cin >> size;
datos.setPropertySize(size);
cout<<"please insert your RoomType:"<<endl;
cin >> roomtype;
datos.setRoomType(roomtype);
cout<<"please insert your Location:"<<endl;
cin >> location;
datos.setLocation(location);
cout<<"please insert your Selling Price:"<<endl;
cin >> sellingprice;
datos.setSellingPrice(sellingprice);
l.push_back(datos);
}
void OrderList(std::list<Data> &l)
{
char resp;
do{
cout<<"What order do you want? ascending=a or descending=d"<<endl;
cin>> resp;
if(resp!='a'&&resp!='d')
{
cout<<"ERROR, Please be careful"<<endl;
}
}while(resp!='a'&&resp!='d');
l.sort();
if(resp=='d'){
l.reverse();
}
}
bool findpass(string pass, string id)
{
string pas,ag;
bool found=false;
std::ifstream passwords;
passwords.open("passwords.in");
while(!passwords.eof() && !found) // To get you all the lines.
{
passwords>>pas>>ag;
if(pass==pas && ag == id)
{
found=true;
}
}
passwords.close();
return found;
}
bool login(string agentid,string password )
{
bool pass,granted =false;
pass=findpass(password,agentid);
if(pass)
{
cout<<"access granted"<<endl;
granted=true;
}else{
cout<<"\nLogin Failed!!\n";
}
return (granted);
}
void changepass(string id)
{
std::list<string> passw,agentid;
string pas,ag;
std::ifstream passwords;
std::ofstream p;
passwords.open("passwords.in");
while(!passwords.eof())
{
passwords>>pas>>ag;
passw.push_back(pas);
agentid.push_back(ag);
}
passwords.close();
cout<<"just for security i will need you to re-login"<<endl;
cout<<"what is your current pass"<<endl;
cin>>pas;
p.open("passwords.in");
if(login(id,pas))
{
cout<<"access granted , please input the new password"<<endl;
cin>>pas;
while(agentid.empty())
{
p<<passw.pop_front();
}
}
}
char menu ()
{
char option;
cout<<"Menu"<<endl;
cout<<"(a) Add new property"<<endl;
cout<<"(b) Remove property "<<endl;
cout<<"(c) Edit sales entries"<<endl;
cout<<"(d) Inquire or search property sales"<<endl;
cout<<"(e) Monthly property sales transaction report"<<endl;
cout<<"(f) List property sale items in ascending or descending order"<<endl;
cout<<"(g) Administration - add / remove property agent"<<endl;
cout<<"(h) Administration - change password"<<endl;
cout<<"(i) Quit"<<endl;
cin>>option;
return (option);
}
void load(std::list<Data> l)
{
Data datos;
int i=0;
unsigned int encontro,anterior;
std::string STRING,agentid,contact,size,roomtype,location,sellingprice;
std::ifstream infile;
infile.open ("data.in");
while(!infile.eof()) // To get you all the lines.
{
getline(infile,STRING); // Saves the line in STRING.
encontro = STRING.find(':', 0);
if(encontro != std::string::npos )
{
agentid = STRING.substr(0, encontro);
datos.setAgentId(agentid);
}
anterior=encontro+1;
encontro= STRING.find(':', anterior);
if(encontro != std::string::npos )
{
contact = STRING.substr(anterior, encontro-anterior);
datos.setContact(contact);
}
anterior=encontro+1;
encontro= STRING.find(':', anterior);
if(encontro != std::string::npos )
{
size = STRING.substr(anterior, encontro-anterior);
datos.setPropertySize(size);
}
anterior=encontro+1;
encontro= STRING.find(':', anterior+1);
if(encontro != std::string::npos )
{
roomtype = STRING.substr(anterior, encontro-anterior);
datos.setRoomType(roomtype);
}
anterior=encontro+1;
encontro= STRING.find(':', anterior+1);
if(encontro != std::string::npos )
{
location = STRING.substr(anterior, encontro-anterior);
datos.setLocation(location);
}
anterior=encontro+1;
sellingprice= STRING.substr(anterior, STRING.length()-anterior);
datos.setSellingPrice(sellingprice);
l.push_back(datos); //Saved each data from "data.in" to the end of the list
i++;
}
infile.close();
}
void show()
{
char option;
do{
cout<<"please insert (a) to see the list in ascending order"<<endl;
cout<<"please insert (b) to see the is in descending order"<<endl;
cout<<"else for returning to main menu"<<endl;
cin>>option;
switch (option)
{
case 'a':
break;
case 'b':
break;
default:option=' ';
}
}while(option!=' ' &&option !='a' &&option!='b');
}
int main()
{
std::list<Data> l;
string agentid,password;
cout<<"please insert your AgentID"<<endl;
cin>>agentid;
cout<<" please insert your password"<<endl;
cin>>password;
if(login(agentid,password)){
load(l);
char option ; // the variable used for storing the users option data
do{
option=menu();
switch (option)
{
case 'a':
break;
case 'b':
break;
case 'c':
break;
case 'd':
break;
case 'e':
break;
case 'f':
show();
break;
case 'g':
break;
case 'i': cout<<"good bye"<<endl;
break;
case 'h':changepass(agentid);
break;
break;
default:cout<<"wrong selection"<<endl;
}
}while(option!='i');
}
return (0);
}