1 #include <fstream>
2 #include "tools.h"
3 #include "class.h"
4
5 using namespace std;
6
7 Customer* cust[30];
8 Room* room[30];
9
10
11 int live; // 被订房间数
12
13 // 获取room_num
14 short Room::get_room_num(void)
15 {
16 return room_num;
17 }
18
19 // 返回房间的下标
20 int Manage::room_index(short room_num)
21 {
22 short num = room_num;
23 for(int i=0; i<30; i++)
24 {
25 if(num == room[i]->get_room_num())
26 {
27 return i;
28 }
29 }
30 return -1;
31 }
32
33 // 返回顾客的下标
34 int Manage::cust_index(short room_num)
35 {
36 short num = room_num;
37 for(int i=0; i<30; i++)
38 {
39 if(num == cust[i]->room_num)
40 {
41 return i;
42 }
43 }
44 return -1;
45 }
46
47 // 查询剩余房间
48 void Manage::find_room(void)
49 {
50 for(int i=0; i<30; i++)
51 {
52 if(i == 10 || i == 20)
53 {
54 cout << endl;
55 }
56 if(room[i]->use != 0)
57 {
58 continue;
59 }
60 cout << room[i]->room_num << " ";
61 }
62 cout << endl;
63 }
64
65 // 开房
66 void Manage::get_room(void)
67 {
68 cout << "现有房间如下" << endl;
69 find_room();
70
71 // cout << "已经入住的人员" << endl;
72 // show_cust();
73
74 cout << "请输入您选择的房间:";
75 short room_num;
76 cin >> room_num;
77 int flag = used(room_num);
78 if(flag == 1)
79 {
80 cout << "此房间不能使用,请重新选择" << endl;
81 getch();
82 return;
83 }
84 else if(flag == -1)
85 {
86 cout << "此房间不存在,请重新选择" << endl;
87 getch();
88 return;
89 }
90 else
91 {
92 cout << "您选择的房间是:" << room_num << endl;
93 }
94
95 int index = room_index(room_num);
96 short type = room[index]->room_type;
97
98 cout << "请输入您的姓名:";
99 string name;
100 cin >> name;
101 cout << "请输入您的身份证:";
102 string id;
103 cin >> id;
104 cout << "请输入您的2位家属(0,表示没有)" << endl;
105 string family1,family2;
106 cin >> family1 >> family2;
107
108 if(type == 1)
109 {
110 if(family1 != "0" || family2 != "0")
111 {
112 cout << "人数过多,开房失败" << endl;
113 getch();
114 return;
115 }
116 }
117 else if(type == 2)
118 {
119 if(family1 != "0" && family2 != "0")
120 {
121 cout << "人数过多,开房失败" << endl;
122 getch();
123 return;
124 }
125 }
126 else
127 {
128 }
129
130 cout << "请输入要订的天数:";
131 short day;
132 cin >> day;
133 short pay = day*room[index]->price;
134 cout << "请支付" << pay << "元" << endl;
135 short money = 0,change = 0;
136 cout << "收您:";
137 cin >> money;
138 cout << "元" << endl;
139 change = money-pay;
140 if(change < 0)
141 {
142 cout << "余额不足,请充值" << endl;
143 getch();
144 return;
145 }
146 cout << "找您" << change << "元" << endl;
147
148 short floor = room_num/100;
149
150 cust[live++] = new Customer(name,id,family1,family2,floor,room_num,day);
151
152 cout << "已订房间:" << live << endl;
153
154 for(int i=0; i<30; i++)
155 {
156 if(room[i]->room_num == room_num)
157 {
158 room[i]->use = 1;
159 }
160 }
161
162 cout << "开房成功,欢迎您的入住,祝你生活愉快!" << endl;
163 getch();
164 }
165
166 // 使用情况
167 int Manage::used(short room_num)
168 {
169 short num = room_num;
170 for(int i=0; i<30; i++)
171 {
172 if(num == room[i]->room_num)
173 {
174 if(room[i]->use == 1)
175 {
176 return 1;
177 }
178 else
179 {
180 return 0;
181 }
182 }
183 }
184 return -1;
185 }
186
187 // 显示顾客
188 void Manage::show_cust(void)
189 {
190 for(int i=0; i<30; i++)
191 {
192 if(cust[i]->name == "0")
193 {
194 break;
195 }
196 else
197 {
198 cout << "姓名:" << cust[i]->name << "," << "房间:" << cust[i]->room_num << ",";
199
200 string f1,f2;
201 f1 = cust[i]->family1;
202 f2 = cust[i]->family2;
203 cout << "家属1:";
204 if(f1 == "0") cout << " ,";
205 else cout << f1 << ",";
206 cout << "家属2:";
207 if(f2 == "0") cout << " ";
208 else cout << f2;
209 }
210 }
211 }
212
213 // 房间价格
214 int Manage::room_price(short room_num)
215 {
216 short num = room_num;
217 for(int i=0; i<30; i++)
218 {
219 if(room[i]->room_num == num)
220 {
221 return room[i]->price;
222 }
223 }
224 return 0;
225 }
226
227 // 续费
228 void Manage::renew_room(void)
229 {
230 cout << "请输入你的房间号:";
231 short room_num;
232 cin >> room_num;
233 int flag = used(room_num);
234 if(flag == -1 || flag == 0)
235 {
236 cout << "您输入的房间号有误" << endl;
237 getch();
238 return;
239 }
240
241 int index = cust_index(room_num);
242
243 cout << "您的房间剩余:" << cust[index]->day << "天" << endl;
244
245 cout << "请输入你要续的天数:";
246 short day;
247 cin >> day;
248 short pay = day*room_price(room_num);
249 cout << "请支付" << pay << "元" << endl;
250 short price = 0,change = 0;
251 cin >> price;
252 change = price-pay;
253 if(change < 0)
254 {
255 cout << "余额不足,请充值" << endl;
256 getch();
257 return;
258 }
259 cout << "收您" << price <<"元,找您" << change << "元" << endl;
260
261 string rename = cust[index]->name,reid = cust[index]->id;
262 string refamily1=cust[index]->family1,refamily2=cust[index]->family2;
263 short refloor = cust[index]->floor,reday = cust[index]->day+day;
264 cust[index] = new Customer(rename,reid,refamily1,refamily2,refloor,room_num,reday);
265
266 cout << "续费成功,房间的使用时间为:" << reday <<"天" << endl;
267 getch();
268
269 }
270
271 // 退房
272 void Manage::cancel_room(void)
273 {
274 cout << "请输入您的房间号:";
275 short room_num;
276 string name;
277 cin >> room_num;
278 cout << "请输入您的姓名:";
279 cin >> name;
280 int flag = used(room_num);
281 if(flag == 0 || flag == -1)
282 {
283 cout << "您输入的房间有误。" << endl;
284 getch();
285 return;
286 }
287 else
288 {
289 short refloor = 0,retype = 0,reprice = 0;
290
291 int i = cust_index(room_num);
292 if(i != -1)
293 {
294 if(cust[i]->name == name)
295 {
296 short price = room[room_index(room_num)]->price;
297 short change = cust[i]->day*price;
298 cout << "退还您" << change << "元" << endl;
299
300 cust[i] = new Customer("0","0","0","0",0,0,0);
301 int j = room_index(room_num);
302 refloor = room[j]->floor;
303 retype = room[j]->room_type;
304 reprice = room[j]->price;
305 room[j] = new Room(refloor,room_num,retype,reprice,0);
306
307 cout << "退房成功,感谢您的光顾,欢迎下次光临!"<< endl;
308 live--;
309 getch();
310 return;
311 }
312 else
313 {
314 //cout << cust[i]->name << endl;
315 cout << "您输入的相关信息有误" << endl;
316 getch();
317 return;
318 }
319 }
320 else
321 {
322 cout << "您输入的信息有误" << endl;
323 getch();
324 return;
325 }
326 }
327 }
328
329 // 顾客初始化
330 void Manage::c_init(void)
331 {
332 fstream ci("data/cust.txt",ios::in);
333 if(!ci.good())
334 {
335 cout << "cust.txt数据加载异常" << endl;
336 }
337
338 for(int i=0; i<30; i++)
339 {
340 string name,id,family1,family2;
341 short floor,room_num,day;
342 ci >> name >> id >> family1 >> family2;
343 ci >> floor >> room_num >> day;
344 cust[i] = new Customer(name,id,family1,family2,floor,room_num,day);
345 if(name != "0")
346 {
347 live++;
348 }
349 }
350 }
351
352 // 房间初始化
353 void Manage::r_init(void)
354 {
355 live = 0;
356 fstream ri("data/room.txt",ios::in);
357 if(!ri.good())
358 {
359 cout << "room.txt数据加载异常" << endl;
360 }
361
362 for(int i=0; i<30; i++)
363 {
364 short floor,room_num,room_type,price,use;
365 ri >> floor >> room_num;
366 ri >> room_type >> price >> use;
367 room[i] = new Room(floor,room_num,room_type,price,use);
368 }
369 }
370
371 // 数据保存
372 void Manage::save_data(void)
373 {
374 fstream co("data/cust.txt",ios::out);
375 fstream ro("data/room.txt",ios::out);
376
377 for(int i=0; i<30; i++)
378 {
379 co << cust[i]->name << " " << cust[i]->id << " ";
380 co << cust[i]->family1 << " " << cust[i]->family2 << " ";
381 co << cust[i]->floor << " " << cust[i]->room_num << " ";
382 co << cust[i]->day << "\n";
383
384 ro << room[i]->floor << " " << room[i]->room_num << " ";
385 ro << room[i]->room_type << " " << room[i]->price << " ";
386 ro << room[i]->use << "\n";
387 }
388 }
389
390 // 菜单
391 void Manage::menu(void)
392 {
393 cout << "***欢迎使用酒店管理系统***" << endl;
394 cout << " 1、查询房间" << endl;
395 cout << " 2、开房" << endl;
396 cout << " 3、续费" << endl;
397 cout << " 4、退房" << endl;
398 cout << " 0、退出系统" << endl;
399 cout << "-----------------------" << endl;
400 }