-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.cpp
269 lines (268 loc) · 6.91 KB
/
account.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
#pragma once
#include<iostream>
#include<fstream>
#include<string>
#include"Hashtable.cpp"
#include"heap.cpp"
#include"avl.cpp"
#include"list.cpp"
using namespace std;
// void add_friend()
// {bool token=false;
// string arr="\0";
// do
// {
// cout<<"Enter the name of friend : ";
// getline(cin,arr);
// if(source.account_search(arr)==NULL)
// {
// cout<<"The "<<arr<<" has not found in system"<<endl;
// continue;
// }
// obj.events.insert(arr);
// } while (source.account_search(arr)==NULL||arr!="0");
// }
// template<class T>
class account
{
string username,password,class_year,name;
heap<string> events;
avl<string> friends;
list<string> timeline;
public:
account()
{
username="\0";
password="\0";
class_year="\0";
name="\0";
}
void set_username(ifstream& fin,string username)
{
this->username=username;
//getline(fin,this->username,'\n');
}
void set_password(ifstream& fin)
{
getline(fin,password,'\n');
}
void set_name(ifstream& fin)
{
getline(fin,name,'\n');
}
void set_class_year(ifstream& fin)
{
getline(fin,class_year,'\n');
}
void set_events(ifstream& fin)
{
string data = "\0",arr ="\0";
getline(fin,arr,'\n');
int count=0,a=0;
do{
if(arr[a]!=','&&arr[a]!='\0')
{
data=data+arr[a];
}
else
{
if(data!="\0")
events.insert(data);
// cout<<data<<"/";
data="\0";
}
}while(arr[a++]!='\0');
events.heapsort();
}
void set_friends(ifstream& fin)
{
string data = "\0",arr ="\0";
getline(fin,arr,'\n');
int count=0,a=0;
do{
if(arr[a]!=','&&arr[a]!='\0')
{
data=data+arr[a];
}
else
{
if(data!="\0")
friends.set_root(friends.insert(friends.get_root(), data));
// cout<<data<<"/";
data="\0";
}
}while(arr[a++]!='\0');
}
void set_timeline(ifstream& fin)
{
string data = "\0",arr ="\0";
getline(fin,arr,'\n');
int count=0,a=0;
do{
if(arr[a]!=','&&arr[a]!='\0')
{
data=data+arr[a];
}
else
{
if(data!="\0")
timeline.insert(data);
// cout<<data<<"/";
data="\0";
}
}while(arr[a++]!='\0');
}
void get_username(ofstream& fout)
{
fout<<username<<"\n";
}
void get_password(ofstream& fout)
{
fout<<password<<"\n";
}
void get_name(ofstream& fout)
{
fout<<name<<"\n";
}
void get_class_year(ofstream& fout)
{
fout<<class_year<<"\n";
}
void get_events(ofstream& fout)
{
events.write_heap(fout);
fout<<"\n";
}
void get_friends(ofstream& fout)
{
friends.avl_write(fout,friends.get_root());
fout<<"\n";
}
void get_timeline(ofstream& fout)
{
timeline.list_write(fout);
fout<<"\n";
}
void operator = (account& obj)
{
username=obj.username;
password=obj.password;
name=obj.name;
class_year=obj.class_year;
events=obj.events;
friends=obj.friends;
timeline=obj.timeline;
}
void in_username(string username)
{
this->username=username;
}
void in_password(string password)
{
this->password=password;
}
void in_name(string name)
{
this->name=name;
}
void in_class_year(string class_year)
{
this->class_year=class_year;
}
void in_events(heap<string> events)
{
this->events=events;
}
string out_username()
{
return username;
}
string out_password()
{
return password;
}
string out_name()
{
return name;
}
string out_class_year()
{
return class_year;
}
heap<string>& out_events()
{
return events;
}
avl<string>& out_friends()
{
return friends;
}
list<string>& out_timeline()
{
return timeline;
}
void getting_data(ifstream& fin, string username)
{
set_username(fin,username);
set_password(fin);
set_name(fin);
set_class_year(fin);
set_events(fin);
// events.heapsort();
set_friends(fin);
set_timeline(fin);
}
friend ofstream& operator<<(ofstream& fout,account& obj);
friend ostream& operator<<(ostream& out,account& obj);
// friend istream& operator>>(istream& in,account& obj);
};
ofstream& operator<<(ofstream& fout,account& obj)
{
obj.get_username(fout);
obj.get_password(fout);
obj.get_name(fout);
obj.get_class_year(fout);
obj.get_events(fout);
obj.get_friends(fout);
obj.get_timeline(fout);
return fout;
}
ostream& operator<<(ostream& out,account& obj)
{
out<<obj.out_username()<<endl;
out<<obj.out_password()<<endl;
out<<obj.out_name()<<endl;
out<<obj.out_class_year()<<endl;
obj.out_events().traverse_heap();
out<<endl;
obj.out_friends().avl_traverse(obj.out_friends().get_root());
out<<endl;
obj.out_timeline().traverse();
out<<endl;
return out;
}
// istream& operator>>(istream& in,account& obj)
// {
// string arr="\0";
// cout<<"Enter the username : ";
// getline(in,obj.username);
// cout<<"Enter the password : ";
// getline(in,obj.password);
// do
// {
// cout<<"Enter the name of friend : ";
// getline(cin,arr);
// if(source.account_search(arr)==NULL)
// {
// cout<<"The "<<arr<<" has not found in system"<<endl;
// continue;
// }
// obj.events.insert(arr);
// } while (source.account_search(arr)==NULL||arr!="0");
// do
// {
// cout<<"Enter the friend's email/To quit enter 0 : ";
// getline(in,arr);
// obj.events.insert(arr);
// } while (arr!="0");
// }