Help needed "hotel management program"

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
#include<iostream>
#include<stdio.h>
#include<dos.h>
#include<string.h>
#include <cstdlib>
#include<conio.h>
#define max 100
using namespace std;
//Class Person

class Person
{
public:
char *name;
char *address;
char *phone;
};


class Room
{
public:
char type;
char stype;
char ac;
int roomNumber;
int rent;
int status;
class Person cust;
class Room addRoom(int);
void searchRoom(int);
void deleteRoom(int);
void displayRoom(Room);
};
//Global Declarations

class Room rooms[max];
int count=0;


Room Room::addRoom(int rno)
{
class Room room;
room.roomNumber=rno;
cout<<"\nType AC/Non-AC (A/N) ";
cin>>room.ac;
cout<<"\nType Comfort (S/N)";
cin>>room.type;
cout<<"\nType Size (B/S) ";
cin>>room.stype;
cout<<"\nRent: ";
cin>>room.rent;
room.status=0;
return room;
}


void Room::searchRoom(int rno)
{
int i,found=0;
for(i=0;i<count;i++)
{
if(rooms[i].roomNumber==rno)
{
found=1;
break;
}
}
if(found==1)
{
cout<<"Room Details\n";
if(rooms[i].status==1)
{
cout<<"\nRoom is Reserved";
}
else
{
cout<<"\nRoom is available";
}
displayRoom(rooms[i]);
getch();
}
else
{
cout<<"\nRoom not found";
getch();
}
}


void Room::displayRoom(Room tempRoom)
{
cout<<"\nRoom Number:\t"<<tempRoom.roomNumber;
cout<<"\nType AC/Non-AC (A/N) "<<tempRoom.ac;
cout<<"\nType Comfort (S/N) "<<tempRoom.type;
cout<<"\nType Size (B/S) "<<tempRoom.stype;
cout<<"\nRent: "<<tempRoom.rent;
}



//hotel management protected data
class HotelMgnt:protected Room
{
public:
void reserveRoom();
void getAvailRoom();
void searchPerson(char *);
void generateBill(int);
};



//hotel management reservation of room
void HotelMgnt:: reserveRoom()
{
int i,found=0,rno;

class Room room;
cout<<"\nEnter Room number: ";
cin>>rno;
for(i=0;i<count;i++)
{
if(rooms[i].roomNumber==rno)
{
found=1;
break;
}
}
if(found==1)
{
if(rooms[i].status==1)
{
cout<<"\nRoom is already Reserved";
return;
}
//cout<<"\nEnter Customer Name: ";
//cin>>rooms[i].cust.name;
cout<<"\nEnter Customer Name: ";
cin>>rooms[i].cust.address;
//cout<<"\nEnter Customer Phone Number: ";
//cin>>rooms[i].cust.phone;
rooms[i].status=1;
}
}


//hotel management shows available rooms
void HotelMgnt::getAvailRoom()
{
int i,found=0;
for(i=0;i<count;i++)
{
if(rooms[i].status==0)
{
displayRoom(rooms[i]);
cout<<"\nPress enter for next room";
found=1;
getch();
}
}
if(found==0)
{
cout<<"\nAll rooms are reserved";
getch();
}
}



//hotel management shows all persons that booked a room
void HotelMgnt::searchPerson(char *pname)
{
int i,found=0;
for(i=0;i<count;i++)
{
if(rooms[i].status==1 && stricmp(rooms[i].cust.name,pname)==0)
{
//cout<<"\nCustomer Name:t"<<rooms[i].cust.name;
cout<<"\nRoom Number:t"<<rooms[i].roomNumber;
cout<<"\nName:t"<<rooms[i].cust.address;
//cout<<"\nPhone:t"<<rooms[i].cust.phone;
cout<<"\nPress enter for next record";
found=1;
getch();
}
}
if(found==0)
{
cout<<"\nPerson not found.";
getch();
}
}


//hotel managemt generates the bill of the expenses
void HotelMgnt::generateBill(int roomNum)
{
int i,found=0,days,rno;
float billAmount=0.0;//,other=0.0;
for(i=0;i<count;i++)
{
if(rooms[i].status==1 && rooms[i].roomNumber==roomNum)
{
//cout<<"\nCustomer Name:t"<<rooms[i].cust.name;
cout<<"\nRoom Number:t"<<rooms[i].roomNumber;
cout<<"\nName:t"<<rooms[i].cust.address;
//cout<<"\nPhone:t"<<rooms[i].cust.phone;
//rno = rooms[i].roomNumber;
found=1;
getch();
break;
}
}
if(found==1)
{
cout<<"\nEnter Number of Days:\t";
cin>>days;
billAmount=days * rooms[i].rent;
cout<<"\nTotal Bill Amount:\tLEK. "<<billAmount<<" /";
rooms[i].status=0;
}
getch();
}


//managing rooms (adding and searching available rooms)
void manageRooms()
{
class Room room;
int opt,rno,i,flag=0;
char ch;
do
{
system("cls");
cout<<"Hotel Management\n";
cout<<"\nManage Room";
cout<<"\n1. Add Room";
cout<<"\n2. Search Room";
cout<<"\n3. Back to Main Menu";
cout<<"\nEnter Option:\t";
cin>>opt;


//switch statement
switch(opt)
{
case 1:
cout<<"\nEnter Room Number:t";
cin>>rno;
i=0;
for(i=0;i<count;i++)
{
if(rooms[i].roomNumber==rno)
{
flag=1;
}
}
if(flag==1)
{
cout<<"\nRoom Number is Present.\nPlease enter unique Number";
flag=0;
getch();
}
else
{
rooms[count]=room.addRoom(rno);
count++;
}
break;
case 2:
cout<<"\nEnter room number: ";
cin>>rno;
room.searchRoom(rno);
break;
case 3:
//	 cout<<"Do you want to Exit (Y/N:) ";
//	 cin>>ch;
break;
default:
cout<<"\nPlease Enter correct option";
break;
}
}while(opt!=3);
}
using namespace std;
int main()
{
class HotelMgnt hm;
int i,j,opt,rno;
char ch;
char *pname;
system("cls");
do
{
system("cls");
cout<<"Hotel Management\n";
cout<<"\n1. Manage Rooms";
cout<<"\n2. Reserve Room";
cout<<"\n3. Available Rooms";
cout<<"\n4. Search Person";
cout<<"\n5. Generate Bill";
cout<<"\n6. Exit";
cout<<"\nEnter Option:t";
cin>>opt;
switch(opt)
{
case 1:
manageRooms();
break;
case 2:
if(count==0)
{
cout<<"\nRooms data is not available.\nPlease add the rooms first.";
getch();
}
else
hm.reserveRoom();
break;
case 3:
if(count==0)
{
cout<<"\nRooms data is not available.\nPlease add the rooms first.";
getch();
}
else
hm.getAvailRoom();
break;
case 4:
if(count==0)
{
cout<<"\nRooms data is not available.\nPlease add the rooms first.";
getch();
}
else
{
cout<<"Enter Person Name: ";
cin>>pname;
hm.searchPerson(pname);
}
break;
case 5:
if(count==0)
{
cout<<"\nRooms data is not available.\nPlease add the rooms first.";
getch();
}
else
{
cout<<"Enter Room Number: ";
cin>>rno;
hm.generateBill(rno);
}
break;
case 6:
cout<<"\nTHANK YOU!";
break;
default:
cout<<"\nPlease Enter correct option";
break;
}
}while(opt!=6);
getch();
}


This is a code that i found in internet about hotel management program. I'm a beginner in C++ and my purpose was to compile the code with dev c++ and to understand how it works, but it has some errors that i cannot fix them. I tried everything i know about C++, but no hope. When i compile the program i get no errors and i can use some functions of the program like adding rooms and searching rooms, but when i want to use the reserve room function the program crashes. If someone could compile the program and tell me what the problem is i would really appreciate it. I really want to learn C++ programming language, but i need some help from the pros. p.s(I apologize if the code is not properly indented, because as I sad I'm a beginner). Thank You in Advance
I made like comment, because the program can work like that .
Topic archived. No new replies allowed.