-
Notifications
You must be signed in to change notification settings - Fork 0
/
Student.cpp
288 lines (262 loc) · 6.48 KB
/
Student.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
#include"Student.h"
Student::Student()
{}
Student::Student(string n, string p)
{
this->name = n;
this->password = p;
}
string return_ID(string name)
{
ifstream R_file("student.txt", ios::in);
if (!R_file.is_open())
return "error";
string data;
string ID;
int index = 1;
while (R_file >> data)
{
if((index+2)%3==0) ID = data;
if ((index+1)%3== 0 && name == data) return ID;
index++;
}
R_file.close();
return "error";
}
bool is_Repeated_addition(vector<string>V, string temp)
{
ifstream W_My_order_file(temp, ios::in);
if (!W_My_order_file.is_open())
{
cout <<temp<< "文件不存在" << endl;
return false;
}
string data;
int index = 1;
int is_line = 0;
while (W_My_order_file >> data)
{
if ((index + 3) % 4 == 0 && data == V[0]) is_line++;
if ((index + 2) % 4 == 0 && data == V[1]) is_line++;
if ((index + 1) % 4 == 0 && data == V[2]) is_line++;
if (is_line == 3) return true;
index++;
}
W_My_order_file.close();
return false;
}
void Student::Apply_appointment()
{
string ID = return_ID(this->name);
string temp = ID +"_"+this->name + "_order.txt";
ofstream W_My_order_file(temp, ios::out | ios::app);
ofstream W_order_file("order.txt", ios::out | ios::app);
vector<string>V;
V.resize(3);
int select_type;
while (1)
{
cout << "可选择日期=>" << endl;
cout << "1.周一 2.周二 3.周三 4.周四 5.周五" << endl;
cout << "请选择日期:";
cin >> select_type;
switch (select_type)
{
case 1:V[0] = "周一"; break;
case 2:V[0] = "周二"; break;
case 3:V[0] = "周三"; break;
case 4:V[0] = "周四"; break;
case 5:V[0] = "周五"; break;
default:
cout << "输入的日期错误!" << endl;
continue;
}
break;
}
while (1)
{
cout << "可选择时间段=》" << endl;
cout << "1.上午 2.下午" << endl;
cout << "请选择时间段:";
cin >> select_type;
switch (select_type)
{
case 1:V[1] = "上午"; break;
case 2:V[1] = "下午"; break;
default:
cout << "输入的时间错误!" << endl;
continue;
}
break;
}
while (1)
{
cout << "可选择机房=》" << endl;
cout << "1.一号机房(100)\n2.二号机房(150)\n3.三号机房(200)" << endl;
cout << "请选择机房:";
cin >> select_type;
switch (select_type)
{
case 1:V[2] = "一号机房(100)"; break;
case 2:V[2] = "二号机房(150)"; break;
case 3:V[2] = "三号机房(200)"; break;
default:
cout << "输入的机房序列错误!" << endl;
continue;
}
break;
}
if (is_Repeated_addition(V, temp)) { cout << "已经有重复的预约,请勿重复添加!" << endl; return; }
cout << "机房预约信息添加成功,请耐心等待管理员审核!" << endl;
W_My_order_file << V[0] << " " << V[1] << " " << V[2]<<" "<<"审核中"<< endl;
W_order_file<< V[0] << " " << V[1] <<" "<<ID<<" "<<this->name<<" " << V[2] << " " << "审核中" << endl;
W_order_file.close();
W_My_order_file.close();
}
bool Student::Show_My_appointment()
{
string ID = return_ID(this->name);
string temp = ID + "_" + this->name + "_order.txt";
ifstream R_file(temp, ios::in);
if (!R_file.is_open())
{
cout << "文件为空" << endl;
return false;
}
string data;
int index = 1;
int ID_index = 1;
cout << endl;
cout << "序列 预约日期 时段 机房 状态"<<endl;
while (R_file >> data)
{
if ((index + 3) % 4 == 0) cout << ID_index << " ";
if ((index + 2) % 4 == 0) cout << " ";
if ((index + 1) % 4 == 0) cout << " ";
if (index % 4 == 0) cout << " ";
cout << data << " ";
if (index % 4 == 0) { cout << endl; ID_index++; }
index++;
}
cout << endl;
R_file.close();
return true;
}
void Student::Show_anyone_appointment()
{
ifstream R_file("order.txt", ios::in);
if (!R_file.is_open())
{
cout << "文件为空!" << endl;
return;
}
string data;
int index = 1;
int ID = 1;
cout << endl;
cout << "序列 预约日期 时段 学号 姓名 机房 状态" << endl;
while (R_file >> data)
{
if ((index + 5) % 6 == 0)cout << ID << " ";
if ((index + 4) % 6 == 0) cout << " ";
if ((index + 3) % 6 == 0) cout << " ";
if ((index + 2) % 6 == 0) cout << " ";
if ((index + 1) % 6 == 0) cout << " ";
if (index % 6 == 0) cout << " ";
cout << data << " ";
if (index % 6 == 0) { cout << endl; ID++; }
index++;
}
cout << endl;
R_file.close();
}
void Student::Cancel_appointment()
{
if (!this->Show_My_appointment()) return;
int select_type,tag=0;
cout << "请选择你要取消的预约:" << endl;
cin >> select_type;
string ID = return_ID(this->name);
string temp = ID + "_" + this->name + "_order.txt";
fstream W_Rfile(temp,ios::in|ios::out);
fstream W_R_order_file("order.txt",ios::in|ios::out);
vector<string>V;
V.resize(2);
if (!W_Rfile.is_open())
{
cout <<this->name<< "预约文件未找到!" << endl;
return;
}
else
{
string data;
int index = 1;
int line = 1;
while (W_Rfile >> data)
{
if (index % 4 == 0 && data == "已取消" && line == select_type) { tag = 1; cout << "该预约已经取消,不要重复操作!" << endl; break; }
if (index % 4 == 0) line++;
index++;
}
index = 1;
line = 1;
//要先清空流状态,在才能使用初始化功能
W_Rfile.clear();
W_Rfile.seekg(0);
if (!tag)
{
while (W_Rfile >> data)
{
if ((index + 3) % 4 == 0 && line == select_type) V[0] = data;
if ((index + 2) % 4 == 0 && line == select_type) V[1] = data;
if ((index + 1) % 4 == 0 && line == select_type)
{
W_Rfile.seekp(W_Rfile.tellg());
W_Rfile << " 已取消" << endl;
break;
}
if (index % 4 == 0) line++;
index++;
}
W_Rfile.close();
cout << "预约成功取消!" << endl;
}
}
W_R_order_file.clear();
W_R_order_file.seekg(0);
if (!tag)
{
if (!W_R_order_file.is_open())
{
cout << "预约文件未找到!" << endl;
return;
}
else
{
string data;
int index = 1;
int is_line = 0;
while (W_R_order_file >> data)
{
if ((index + 5) % 6 == 0 && data == V[0]) is_line++;
if ((index + 4) % 6 == 0 && data == V[1]) is_line++;
if ((index + 3) % 6 == 0 && data == ID) is_line++;
if ((index + 2) % 6 == 0 && data == this->name) is_line++;
if ((index + 1) % 6 == 0 && is_line == 4)
{
W_R_order_file.seekp(W_R_order_file.tellg());
W_R_order_file << " 已取消" << endl;
break;
}
if (index % 6 == 0) is_line = 0;
index++;
}
W_Rfile.close();
}
}
}
bool Student::Quit_login()
{
cout << this->name << "同学退出成功,欢迎下次使用!" << endl;
return true;
}