-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hotel.cpp
453 lines (406 loc) · 11.3 KB
/
Hotel.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
#pragma once
#include"Room.cpp"
#include"Invoice.cpp"
#include"Customer.cpp"
#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
#include<conio.h>
#include<iomanip>
using namespace std;
class Hotel {
private:
Customer customer;
Room* rooms = new Room[10];
Invoice bill;
public:
Hotel() {}
~Hotel(){}
void reset_rooms() { //ham nay chi dung 1 lan duy nhat de khoi tao du lieu mac dinh cho cac phong va ghi du lieu vao file,
//nhung lan sau dung se reset lai du lieu cua cac phong va xoa tat ca du lieu ve khach dat phong
// khach san gom 10 phong danh so tu 101 den 110
//khoi tao danh sach phong standard tu 101 den 107
for (int i = 0; i < 7; i++) {
rooms[i].set_room_no(101 + i);
rooms[i].set_status("available");
rooms[i].set_typeRoom("standard");
rooms[i].set_price(200);
}
//khoi tao danh sach phong VIP tu 108 den 110
for (int i = 7; i < 10; i++) {
rooms[i].set_room_no(101 + i);
rooms[i].set_status("available");
rooms[i].set_typeRoom("VIP");
rooms[i].set_price(1000);
}
ofstream file("List_room.txt", ios::trunc);
ofstream file2("Customer_record.txt", ios::trunc);
for (int i = 0; i < 10; i++) {
file << setw(20) << rooms[i].get_room_no()
<< setw(20) << rooms[i].get_type_room()
<< setw(20) << rooms[i].get_price()
<< setw(20) << rooms[i].get_status() << '\n';
}
file.close();
cout << "\n\n\t\t\tPress Any Key To Continue.......";
}
bool check(int roomNum) { // ham check xem phong duoc dat hay chua
bool flag = false;// false phong trong
string line;
string roomNo = to_string(roomNum);
ifstream file("List_room.txt", ios::in);
while (getline(file, line)) {
if (line.find(roomNo) != string::npos) {
if (line.find("unavailable")!=string::npos) {
flag = true;//true la phong duoc dat
break;
}
}
}
file.close();
return flag;
}
void show_list_room() { // ham show danh sach cac phong
cout << "\t\t\t\tList Rooms" << endl;
cout << "\t\t\t********************\n\n";
cout << "\t\tROOM NO" << "\t\tTYPE ROOM" << "\t\tPRICE" << "\t\tSTATUS" << endl;
string line;
ifstream file("List_room.txt", ios::in);
while (getline(file, line)) {
cout << line << endl;
}
file.close();
}
void display_customer_record() {// ham nay tim so phong se ra thong tin khach hang
ifstream file("List_room.txt", ios::in);
cout << "Enter room number: ";
int room_no;
cin >> room_no;
bool flag = check(room_no);
string txtRoomNum = to_string(room_no);
if (flag) {
system("cls");
cout << "\n\n\n";
cout << left << setw(10) <<"Room no"
<< setw(20) << "Name"
<< setw(10) << "Age"
<< setw(10) << "Gender"
<< setw(15) << "Id"
<<setw(15) << "Phone"
<< setw(20)<<"Days Check Out"
<<setw(5)<<"Total"<<endl;
string line;
ifstream file("Customer_record.txt", ios::in);
while (getline(file, line)) {
if (line.find(txtRoomNum) != string::npos) {
cout << line;
break;
}
}
file.close();
}
else
{
system("cls");
cout << "\n\n\t\t\t******************************" << endl;
cout << "\t\t\tSorry!Room Is Vacant OR NOT Exist";
cout << "\n\n\t\t\tPress Any Key To Continue.......";
_getch();
}
}
// day la ham thuc hien book phong
void book_room() {
int r;
cout << "\n\n\t\tCustomer Detail" << endl;
cout << "\t\t***************" << endl;
cout << "\n\nChoose number of room: ";
cin >> r;
if (r < 101 || r > 110) {
system("cls");
cout << "\n\n\n\t\t***************************" << endl;
cout << "\t\tSorry! Room Does NOT Exist!" << endl;
cout << "\t\tPress Any Key To Continue.......";
_getch();
}
else {
bool flag = check(r);
if (flag) {
system("cls");
cout << "\n\n\n\t\t***********************";
cout << "\n\t\tRoom is already booked!";
cout << "\n\n\t\t\tPress Any Key To Continue.......";
_getch();
}
else
{
Invoice::add();
rooms[r - 101].set_room_no(r);
rooms[r - 101].set_status("unavailable");
customer.input();
bill.input();
bill.output(r);
string customer_record;
ofstream file2("Customer_record.txt", ios::app);//dien thong tin cua khach vao file
file2 << left << setw(10)
<< rooms[r - 101].get_room_no()
<< setw(20) << customer.get_name()
<< setw(10) << customer.get_age()
<< setw(10) << customer.get_gender()
<< setw(15) << customer.get_id()
<< setw(15) << customer.get_phone()
<< setw(20) << bill.get_days()
<< setw(5) << bill.get_total() << endl;
file2.close();
string txtRoomNum = to_string(r);
string line;
fstream file("List_room.txt", ios::in | ios::out);
if (file.is_open()) {
ofstream tempFile("temp.txt");
file.seekp(0, 0);
file.seekg(0, 0);
file.clear();
while (getline(file, line)) {
if (line.find(txtRoomNum) != string::npos) {
size_t pos = line.find("available");
if (pos != string::npos) {
line.replace(pos, 9, "unavailable");
}
}
tempFile << line << endl;
tempFile.flush();
}
tempFile.close();
file.close();
remove("List_room.txt");
rename("temp.txt", "List_room.txt");
system("cls");
cout << "\n\n\t\t\t*********************" << endl;
cout << "\t\t\t Successful Booking !";
cout << "\n\n\t\t\tPress Any Key To Continue.......";
_getch();
}
}
}
}
//day la ham doi thong tin khach hang
void modify_record(int roomNum) {
bool flag = check(roomNum);
if (flag) {
string line;
string txtRoomNum = to_string(roomNum);
fstream file2("Customer_record.txt", ios::in | ios::out);
if (file2.is_open()) {
ofstream tempfile("temporary_file.txt", ios::out);
file2.seekg(0, 0);
file2.seekp(0, 0);
file2.clear();
while (getline(file2, line)) {
if (line.find(txtRoomNum) != string::npos) {
size_t pos = line.find(customer.get_name());
cout << "\n\n\t\t\tEnter New Information" << endl;
cout << "\t\t\t*********************" << endl;
customer.input();
bill.input();
tempfile << left << setw(10) << rooms[roomNum-101].get_room_no()
<< setw(20) << customer.get_name()
<< setw(10) << customer.get_age()
<< setw(10) << customer.get_gender()
<< setw(15) << customer.get_id()
<< setw(15) << customer.get_phone()
<< setw(20) << bill.get_days()
<< setw(5) << bill.get_total()<< endl;
tempfile.flush();
}
else {
tempfile << line << endl;
tempfile.flush();
}
}
tempfile.close();
file2.close();
remove("Customer_record.txt");
rename("temporary_file.txt", "Customer_record.txt");
}
}
else {
system("cls");
cout << "\n\n\t\t\t******************************" << endl;
cout << "\t\t\tSorry!Room Is Vacant OR NOT Exist";
cout << "\n\n\t\t\tPress Any Key To Continue.......";
_getch();
}
}
// Day la ham delete thong tin khach hang qua so phong
void delete_record(int roomNum) {
bool flag = check(roomNum);
if (flag) {
string line;
string txtRoomnum = to_string(roomNum);
ifstream file("Customer_record.txt", ios::in);
if (file.is_open()) {
ofstream tempFILE("temporary.txt", ios::out);
file.seekg(0, 0);
file.seekg(0, 0);
file.clear();
while (getline(file, line)) {
if (line.find(txtRoomnum) != string::npos) {
cout << "\n\n\t\t\tDo You Want To Delete ?" << endl;
cout << "\n\t\t\tYES(y) OR NO(n)" << endl;
char choice;
cout << "\n\t\t\tEnter Your Choice: ";
cin >> choice;
switch (choice)
{
case 'y': {
system("cls");
fstream f("List_room.txt", ios::in | ios::out);
ofstream fout("file_tam_thoi.txt", ios::out);
f.seekg(0, 0);
f.seekp(0, 0);
f.clear();
while (getline(f, line)) {
if (line.find(txtRoomnum) != string::npos) {
size_t pos = line.find("unavailable");
if (pos != string::npos) {
line.replace(pos, 11, "available");
}
}
fout << line << endl;
fout.flush();
}
f.close();
fout.close();
remove("List_room.txt");
rename("file_tam_thoi.txt", "List_room.txt");
cout << "\n\n\t\t\tDeleted Successful!";
break;
}
case 'n': {
tempFILE << line << endl;
tempFILE.flush();
break;
}
default:
system("cls");
cout << "\n\n\t\t\tPress Any Key To Return Menu";
break;
}
}
else {
tempFILE << line << endl;
tempFILE.flush();
}
}
file.close();
tempFILE.close();
remove("Customer_record.txt");
rename("temporary.txt", "Customer_record.txt");
}
}
else
{
system("cls");
cout << "\n\n\t\t\tRoom Does NOT Exist!" << endl;
_getch();
}
}
//Day la ham edit thong tin khach hang gom 2 tinh nang la delete va modify
void edit_record()
{
cout << "\n\n\t\t\tEdit Menu" << endl;
cout << "\t\t\t************************" << endl;
cout << "\t\t\t1.Delete Customer Record" << endl;
cout << "\t\t\t2.Modify Customer Record" << endl;
cout << "\t\t\t************************" << endl;
cout << "\nEnter Your Choice: ";
int choice, r;
cin >> choice;
system("cls");
cout << "\n\nEnter Room No: ";
cin >> r;
switch (choice)
{
case 1:
system("cls");
delete_record(r);
break;
case 2:
system("cls");
modify_record(r);
break;
default:
{
system("cls");
cout << "\n\n\t\t\tWrong choice.....!!" << endl;
break;
}
}
cout << "\n\n\t\t\tPress Any Key To Continue.......";
_getch();
}
void main_menu() { // tao menu
int choice = NULL;
while (choice != 6) {
system("cls");
cout << "\t---------------" << endl;
cout << "\t** Main menu **" << endl;
cout << "\t---------------" << endl;
cout << "\n1.Show List Room." << endl;
cout << "2.Book A Room." << endl;
cout << "3.Display Customer Record." << endl;
cout << "4.Edit Record." << endl;
cout << "5.Reset Rooms." << endl;
// chi dung 1 lan duy nhat de khoi tao du lieu cho cac phong va ghi du lieu vao file,
//nhung lan sau dung se reset lai du lieu cua cac phong
cout << "6.Exit.";
cout << "\n\n\nEnter Your Choice:";
cin >> choice;
switch (choice)
{
case 1:
system("cls");
show_list_room();
_getch();
break;
case 2:
system("cls");
book_room();
_getch();
break;
case 3:
system("cls");
display_customer_record();
_getch();
break;
case 4:
system("cls");
edit_record();
_getch();
break;
case 5:
system("cls");
reset_rooms();
_getch();
break;
case 6:
system("cls");
cout << "\n\n";
cout << "\t\t\tThanks For Visiting! Goodbye!" << endl;
cout << "\t\t\t*****************************";
_getch();
break;
default:
{
system("cls");
cout << "\n\n";
cout << "\t\t\tInvalid Choice! " << endl;
cout << "\n\n\t\t\tPress Any Key To Continue.......";
cout << "\n\n\t\t\t********************************";
_getch();
break;
}
}
}
}
};