-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneral Hotel Management.CPP
370 lines (352 loc) · 7.23 KB
/
General Hotel Management.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
// 12 A7 PROJECT 2017
// By The Junk Values
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<process.h>
#include<ctype.h>
class hotel
{
int room_no,days;
char name[30],address[50],phno[10];
public:
void menu();
void addrec(); //To add customer record
void display(); //To display customer record
void rooms(); //To display rooms allotted
void edit(); //To edit customer record
int check(int r); //To check room status
void modify(int r); //To modify record
void delete_rec(int r); //To delete the record
void checkout(); //To bid farewell to the customer
void bill(int r); //To view bill for stay
void checkphno(char phno[]); //To check validity of phone no
}h;
void hotel::menu()
{
int c;
clrscr();
cout<<endl<<"\t\t\t ************************";
cout<<endl<<"\t\t\t * THE JUNK VALUE HOTEL *";
cout<<endl<<"\t\t\t ************************";
cout<<endl<<endl<<"\t\t\t 1. Book a room";
cout<<endl<<"\t\t\t 2. View customer record";
cout<<endl<<"\t\t\t 3. Rooms allotted";
cout<<endl<<"\t\t\t 4. Edit record";
cout<<endl<<"\t\t\t 5. Exit";
cout<<endl<<endl<<"\t\t\t Enter your choice: ";
cin>>c;
switch(c)
{
case 1:
addrec();
break;
case 2:
display();
break;
case 3:
rooms();
break;
case 4:
edit();
break;
case 5:
checkout();
break;
default:
cout<<"\t\t Invalid choice";
break;
}
}
void hotel::addrec()
{
clrscr();
int r,flag;
cout<<endl;
cout<<"Room no. \t Suite \t\t\t Price per day";
cout<<endl<<"1 to 35 \t The Quaint Suite \t Rs. 2500";
cout<<endl<<"36 to 70 \t The Special Suite \t Rs. 4000";
cout<<endl<<"71 to 100 \t The Deluxe Suite \t Rs. 6000";
cout<<endl;
ofstream fout("Record.dat",ios::binary|ios::app);
if(!fout)
{
cout<<"Error";
exit(0);
}
else
{
cout<<endl<<"Enter customer details: ";
cout<<endl<<"Enter room no: ";
cin>>r;
flag=check(r);
if(flag)
cout<<"Sorry, the room has already been booked. ";
else
{
room_no=r;
cout<<"Enter name: ";
gets(name);
cout<<"Enter address: ";
gets(address);
cout<<"Enter phone no: ";
gets(phno);
checkphno(phno);
cout<<"Enter no. of days of stay: ";
cin>>days;
fout.write((char*)&h,sizeof(h));
cout<<endl<<"Room has been booked."<<endl<<endl;
bill(r);
}
}
fout.close();
}
void hotel::display()
{
clrscr();
ifstream fin("Record.dat",ios::binary|ios::app);
int r,flag;
cout<<"Enter room no: ";
cin>>r;
if(!fin)
{
cout<<"Error";
exit(0);
}
else
{
while(!fin.eof())
{
fin.read((char*)&h,sizeof(h));
if(room_no==r)
{
clrscr();
cout<<endl<<"Customer Details: ";
cout<<endl<<endl<<"Room no: "<<room_no;
cout<<endl<<"Name: "<<name;
cout<<endl<<"Address: "<<address;
cout<<endl<<"Phone no: "<<phno;
flag=1;
break;
}
}
}
if(flag==0)
cout<<"Sorry, the room no. not found or is unoccupied.";
fin.close();
}
void hotel::rooms()
{
clrscr();
ifstream fin("Record.dat",ios::binary|ios::app);
if(!fin)
{
cout<<"Error";
exit(0);
}
else
{
cout<<"List of Rooms Allotted: ";
cout<<endl<<endl<<"Room no. \tName \t\tAddress \tPhone no. ";
while(!fin.eof())
{
fin.read((char*)&h,sizeof(h));
if(fin.eof())
break;
else
cout<<endl<<room_no<<"\t\t"<<name<<"\t\t"<<address<<"\t\t"<<phno;
}
}
fin.close();
}
void hotel::edit()
{
clrscr();
int c,r;
cout<<"Edit menu: ";
cout<<endl<<"1. Modify customer record";
cout<<endl<<"2. Delete customer record";
cout<<endl<<endl<<"Enter choice: ";
cin>>c;
clrscr();
cout<<"Enter room no: ";
cin>>r;
switch(c)
{
case 1:
modify(r);
break;
case 2:
delete_rec(r);
break;
default:
cout<<"Invalid choice";
break;
}
}
int hotel::check(int r)
{
int flag=0;
ifstream fin("Record.dat",ios::binary|ios::app);
if(!fin)
{
cout<<"Error";
exit(0);
}
else
{
while(!fin.eof())
{
fin.read((char*)&h,sizeof(h));
if(room_no==r)
{
flag=1;
break;
}
}
}
fin.close();
return flag;
}
void hotel::modify(int r)
{
int flag=0;
fstream file("Record.dat",ios::binary|ios::in|ios::out);
if(!file)
{
cout<<"Error";
exit(0);
}
else
{
while(!file.eof())
{
file.read((char*)&h,sizeof(h));
if(room_no==r)
{
cout<<endl<<"Enter new details: ";
cout<<endl<<"Enter name: ";
gets(name);
cout<<"Enter address: ";
gets(address);
cout<<"Enter phone no: ";
gets(phno);
checkphno(phno);
cout<<"Enter no. of days of stay: ";
cin>>days;
file.seekp(file.tellp()-sizeof(h),ios::beg);
file.write((char*)&h,sizeof(h));
cout<<endl<<"Record has been modified."<<endl<<endl;
bill(r);
flag=1;
break;
}
}
}
if(flag==0)
cout<<"Sorry, room no. not found or is unoccupied.";
file.close();
}
void hotel::delete_rec(int r)
{
int flag=0;
ifstream fin("Record.dat",ios::binary);
ofstream fout("Temp.dat",ios::binary);
if(!fin||!fout)
{
cout<<"Error";
exit(0);
}
else
{
while(!fin.eof())
{
fin.read((char*)&h,sizeof(h));
if(fin.eof())
break;
else
{
if(room_no!=r)
{
fout.write((char*)&h,sizeof(h));
flag=1;
}
}
}
if(flag==0)
cout<<"Sorry, room no. not found or is unoccupied.";
else
cout<<endl<<"Record has been deleted.";
fin.close();
fout.close();
}
remove("Record.dat");
rename("Temp.dat","Record.dat");
}
void hotel::checkout()
{
clrscr();
cout<<endl<<"\t\t THANK YOU FOR CHECKING IN AT OUR HOTEL!";
cout<<endl<<"\t\t WE HOPE TO SEE YOU AGAIN LATER."<<endl;
getch();
exit(0);
}
void hotel::bill(int r)
{
if((r>=1)&&(r<=35))
cout<<"The bill for your stay is Rs. "<<days*2500.00;
else if((r>=36)&&(r<=70))
cout<<"The bill for your stay is Rs. "<<days*4000.00;
else if((r>=71)&&(r<=100))
cout<<"The bill for your stay is Rs. "<<days*6000.00;
else
cout<<"Room no. not in hotel.";
}
void hotel::checkphno(char phno[])
{
for(int i=0;phno[i]!='\0';i++)
{
if(isdigit(phno[i]))
continue;
else
{
cout<<"Enter a valid phone number: ";
gets(phno);
break;
}
}
if(i==10)
return;
else
{
cout<<"Enter a valid phone number: ";
gets(phno);
}
}
void main()
{
clrscr();
char rep;
cout<<endl<<"\t\t\t****************************";
cout<<endl<<"\t\t\t* HOTEL MANAGEMENT PROJECT *";
cout<<endl<<"\t\t\t****************************";
cout<<endl;
cout<<endl<<"\t\t\tMade by the Junk Values: ";
cout<<endl<<"\t\t\tJ. Neythra \t 41";
cout<<endl<<"\t\t\tS. Pooja \t 43";
cout<<endl<<"\t\t\tS. Varsha \t 47";
cout<<endl<<"\t\t\tK. Visalya \t 48"<<endl;
cout<<endl<<"\t\t\tPress any key to continue. ";
getch();
do
{
h.menu();
cout<<endl<<endl<<"Do you wish to continue? (Enter y/n): ";
cin>>rep;
} while((rep=='y')||(rep=='Y'));
if((rep=='n')||(rep=='N'))
h.checkout();
else
cout<<"Enter a valid response please. (Enter y/n)";
}