Hotel Management System in C++
Hotel Management System in C++
Computational Science
School of Information Science
Introduction to Management
Assignment
(Section 3)
Group members:
Dandy Herko --------------------------UGR/3573/15
Beshah Ashenafi ------------------------UGR/5569/15
Elshaday Bilelign ----------------------UGR/4850/15
Kenbon Leta ----------------------------UGR/8977/14
Melat Mamushet -----------------------UGR/3703/15
o Manage Rooms
o Check-In
o Get available rooms
o Search customer
o Check-out room
o Get guest summary report
Program Breakdown
#include <iostream>
#include <string.h>
#include <conio.h>
#define max 100
using namespace std;
We will going to include all the necessary library files to avoid any kind of error and pre defining max to be 100.
class Customer
{
public:
char name[100];
char address[100];
char phone[12];
char from_date[20];
char to_date[20];
float payment_advance;
10. int booking_id;
11. };
We have created a class for customer having variables like name of size 100, address of size 100, phone of character up to 12, from date of size 20, to_date of size 20, a float payment_advance
variable and a booking_id of type int.
class Room
{
public:
char type;
char stype;
char ac;
int roomNumber;
int rent;
int status;
10.
11. class Customer cust;
12. class Room addRoom(int);
13. void searchRoom(int);
14. void deleteRoom(int);
15. void displayRoom(Room);
16. };
We have declared a class room having the variables like type, stype, ac, roomNumber of type int, rent of type int and status of type int. We have created a object of the customer class cust.
In the function addroom, an object of class room is created which will be responsible to add the rooms according to customer need and will ask for type AC or NOT then ask for comfort and size of
room S or B and daily rent which we will going to set as per need. Rooms added successfully.
This function search room will help in finding existed room if available. The customer will enter the room number, if the room is found it will show the details of the room.
This function will display the rooms only when the customer will enter the room number and chose the type AC or not and comfort and type size etc.
This will going to be the class for hotel management having options like check-in, available rooms, search for a customer, check out and getting the summary report.
void HotelMgnt::guestSummaryReport()
{
if (count == 0)
{
cout << "\n No Guest in Hotel !!";
}
for (int i = 0; i < count; i++)
{
10. if (rooms[i].status == 1)
11. {
12. cout << "\n Customer First Name : " << rooms[i].cust.name;
13. cout << "\n Room Number : " << rooms[i].roomNumber;
14. cout << "\n Address (only city) : " << rooms[i].cust.address;
15. cout << "\n Phone : " << rooms[i].cust.phone;
16. cout << "\n---------------------------------------";
17. }
18. }
The function above getsummary will get us the summary of a existed customer if present any and we can add the summary as well. It will ask for customer first name, room number, address and
phone number.
If a customer wants to make a reservation then this code will come in action. The customer will enter the room number; if that room is booked then system will flag a text showing room is already
booked. If the room was not booked the system will ask for booking id, customer name, ask for enter the address, enter the phone number, enter the date you want to take the room and for enter
the advance payment. Then the system will flag a text showing Customer checked in successfully.
void HotelMgnt::getAvailRoom()
{
int i, found = 0;
for (i = 0; i < count; i++)
{
if (rooms[i].status == 0)
{
displayRoom(rooms[i]);
cout << "\n\nPress enter for next room";
10. found = 1;
11. getch();
12. }
13. }
14. if (found == 0)
15. {
16. cout << "\nAll rooms are reserved";
17. getch();
18. }
19. }
The above function will show the available rooms, if that room found to be reserved system shows a flag stating that all rooms are reserved.
The above peace of code will go to search for a customer. The user will enter the customer name and if the customer doesn't exist it will show person not found.
void manageRooms()
{
class Room room;
int opt, rno, i, flag = 0;
char ch;
do
{
system("cls");
cout << "\n### Manage Rooms ###";
10. cout << "\n1. Add Room";
11. cout << "\n2. Search Room";
12. cout << "\n3. Back to Main Menu";
13. cout << "\n\nEnter Option: ";
14. cin >> opt;
15.
16. // switch statement
17. switch (opt)
18. {
19. case 1:
20. cout << "\nEnter Room Number: ";
21. cin >> rno;
22. i = 0;
23. for (i = 0; i < count; i++)
24. {
25. if (rooms[i].roomNumber == rno)
26. {
27. flag = 1;
28. }
29. }
30. if (flag == 1)
31. {
32. cout << "\nRoom Number is Present.\nPlease enter unique Number";
33. flag = 0;
34. getch();
35. }
36. else
37. {
38. rooms[count] = room.addRoom(rno);
39. count++ ;
40. }
41. break;
42. case 2 :
43. cout << " \ n Enter room number : " ;
44. cin >> rno ;
45. room.searchRoom ( rno ) ;
46. break ;
47. case 3 :
48. // nothing to do
49. Break ;
50. default :
51. cout << " \ n Please Enter correct option " ;
52. break ;
53. }
54. } while ( opt != 3 ) ;
55. }
The above peace of code is used to manage the rooms like, adding rooms or search room or back to menu.
#include <iostream>
#include <string.h>
#include <conio.h>
#define max 100
using namespace std;
// Class Customer
class Customer
{
public:
10. char name[100];
11. char address[100];
12. char phone[12];
13. char from_date[20];
14. char to_date[20];
15. float payment_advance;
16. int booking_id;
17. };
18. class Room
19. {
20. public:
21. char type;
22. char stype;
23. char ac;
24. int roomNumber;
25. int rent;
26. int status;
27.
28. class Customer cust;
29. class Room addRoom(int);
30. void searchRoom(int);
31. void deleteRoom(int);
32. void displayRoom(Room);
33. };
34.
35. // Global Declarations
36. class Room rooms[max];
37. int count = 0;
38.
39. Room Room::addRoom(int rno)
40. {
41. class Room room;
42. room.roomNumber = rno;
43. cout << "\nType AC/Non-AC (A/N) : ";
44. cin >> room.ac;
45. cout << "\nType Comfort (S/N) : ";
46. cin >> room.type;
47. cout << "\nType Size (B/S) : ";
48. cin >> room.stype;
49. cout << "\nDaily Rent : ";
50. cin >> room.rent;
51. room.status = 0;
52.
53. cout << "\n Room Added Successfully!";
54. getch();
55. return room;
56. }
57. void Room::searchRoom(int rno)
58. {
59. int i, found = 0;
60. for (i = 0; i < count; i++)
61. {
62. if (rooms[i].roomNumber == rno)
63. {
64. found = 1;
65. break;
66. }
67. }
68. if (found == 1)
69. {
70. cout << "Room Details\n";
71. if (rooms[i].status == 1)
72. {
73. cout << "\nRoom is Reserved";
74. }
75. else
76. {
77. cout << "\nRoom is available";
78. }
79. displayRoom(rooms[i]);
80. getch();
81. }
82. else
83. {
84. cout << "\nRoom not found";
85. getch();
86. }
87. }
88.
89. void Room::displayRoom(Room tempRoom)
90. {
91. cout << "\nRoom Number: \t" << tempRoom.roomNumber;
92. cout << "\nType AC/Non-AC (A/N) " << tempRoom.ac;
93. cout << "\nType Comfort (S/N) " << tempRoom.type;
94. cout << "\nType Size (B/S) " << tempRoom.stype;
95. cout << "\nRent: " << tempRoom.rent;
96. }
97.
98. // hotel management class
99. class HotelMgnt : protected Room
100. {
101. public:
102. void checkIn();
103. void getAvailRoom();
104. void searchCustomer(char *);
105. void checkOut(int);
106. void guestSummaryReport();
107. };
108.
109. void HotelMgnt::guestSummaryReport()
110. {
111.
112. if (count == 0)
113. {
114. cout << "\n No Guest in Hotel !!";
115. }
116. for (int i = 0; i < count; i++)
117. {
118. if (rooms[i].status == 1)
119. {
120. cout << "\n Customer First Name : " << rooms[i].cust.name;
121. cout << "\n Room Number : " << rooms[i].roomNumber;
122. cout << "\n Address (only city) : " << rooms[i].cust.address;
123. cout << "\n Phone : " << rooms[i].cust.phone;
124. cout << "\n---------------------------------------";
125. }
126. }
127.
128. getch();
129. }
130.
131. // hotel management reservation of room
132. void HotelMgnt::checkIn()
133. {
134. int i, found = 0, rno;
135.
136. class Room room;
137. cout << "\nEnter Room number : ";
138. cin >> rno;
139. for (i = 0; i < count; i++)
140. {
141. if (rooms[i].roomNumber == rno)
142. {
143. found = 1;
144. break;
145. }
146. }
147. if (found == 1)
148. {
149. if (rooms[i].status == 1)
150. {
151. cout << "\nRoom is already Booked";
152. getch();
153. return;
154. }
155.
156. cout << "\nEnter booking id: ";
157. cin >> rooms[i].cust.booking_id;
158.
159. cout << "\nEnter Customer Name (First Name): ";
160. cin >> rooms[i].cust.name;
161.
162. cout << "\nEnter Address (only city): ";
163. cin >> rooms[i].cust.address;
164.
165. cout << "\nEnter Phone: ";
166. cin >> rooms[i].cust.phone;
167.
168. cout << "\nEnter From Date: ";
169. cin >> rooms[i].cust.from_date;
170.
171. cout << "\nEnter to Date: ";
172. cin >> rooms[i].cust.to_date;
173.
174. cout << "\nEnter Advance Payment: ";
175. cin >> rooms[i].cust.payment_advance;
176.
177. rooms[i].status = 1;
178.
179. cout << "\n Customer Checked-in Successfully..";
180. getch();
181. }
182. }
183.
184. // hotel management shows available rooms
185. void HotelMgnt::getAvailRoom()
186. {
187. int i, found = 0;
188. for (i = 0; i < count; i++)
189. {
190. if (rooms[i].status == 0)
191. {
192. displayRoom(rooms[i]);
193. cout << "\n\nPress enter for next room";
194. found = 1;
195. getch();
196. }
197. }
198. if (found == 0)
199. {
200. cout << "\nAll rooms are reserved";
201. getch();
202. }
203. }
204.
205. // hotel management shows all persons that have booked room
206. void HotelMgnt::searchCustomer(char *pname)
207. {
208. int i, found = 0;
209. for (i = 0; i < count; i++)
210. {
211. if (rooms[i].status == 1 && stricmp(rooms[i].cust.name, pname) == 0)
212. {
213. cout << "\nCustomer Name: " << rooms[i].cust.name;
214. cout << "\nRoom Number: " << rooms[i].roomNumber;
215.
216. cout << "\n\nPress enter for next record";
217. found = 1;
218. getch();
219. }
220. }
221. if (found == 0)
222. {
223. cout << "\nPerson not found.";
224. getch();
225. }
226. }
227.
228. // hotel managemt generates the bill of the expenses
229. void HotelMgnt::checkOut(int roomNum)
230. {
231. int i, found = 0, days, rno;
232. float billAmount = 0;
233. for (i = 0; i < count; i++)
234. {
235. if (rooms[i].status == 1 && rooms[i].roomNumber == roomNum)
236. {
237. // rno = rooms[i].roomNumber;
238. found = 1;
239. // getch();
240. break;
241. }
242. }
243. if (found == 1)
244. {
245. cout << "\nEnter Number of Days:\t";
246. cin >> days;
247. billAmount = days * rooms[i].rent;
248.
249. cout << "\n\t######## CheckOut Details ########\n";
250. cout << "\nCustomer Name : " << rooms[i].cust.name;
251. cout << "\nRoom Number : " << rooms[i].roomNumber;
252. cout << "\nAddress : " << rooms[i].cust.address;
253. cout << "\nPhone : " << rooms[i].cust.phone;
254. cout << "\nTotal Amount Due : " << billAmount << " /";
255. cout << "\nAdvance Paid: " << rooms[i].cust.payment_advance << " /";
256. cout << "\n*** Total Payable: " << billAmount - rooms[i].cust.payment_advance << "/ only";
257.
258. rooms[i].status = 0;
259. }
260. getch();
261. }
262.
263. // managing rooms (adding and searching available rooms)
264. void manageRooms()
265. {
266. class Room room;
267. int opt, rno, i, flag = 0;
268. char ch;
269. do
270. {
271. system("cls");
272. cout << "\n### Manage Rooms ###";
273. cout << "\n1. Add Room";
274. cout << "\n2. Search Room";
275. cout << "\n3. Back to Main Menu";
276. cout << "\n\nEnter Option: ";
277. cin >> opt;
278.
279. // switch statement
280. switch (opt)
281. {
282. case 1:
283. cout << "\nEnter Room Number: ";
284. cin >> rno;
285. i = 0;
286. for (i = 0; i < count; i++)
287. {
288. if (rooms[i].roomNumber == rno)
289. {
290. flag = 1;
291. }
292. }
293. if (flag == 1)
294. {
295. cout << "\nRoom Number is Present.\nPlease enter unique Number";
296. flag = 0;
297. getch();
298. }
299. else
300. {
301. rooms[count] = room.addRoom(rno);
302. count++;
303. }
304. break;
305. case 2:
306. cout << "\nEnter room number: ";
307. cin >> rno;
308. room.searchRoom(rno);
309. break;
310. case 3:
311. // nothing to do
312. break;
313. default:
314. cout << "\nPlease Enter correct option";
315. break;
316. }
317. } while (opt != 3);
318. }
319. using namespace std;
320. int main()
321. {
322. class HotelMgnt hm;
323. int i, j, opt, rno;
324. char ch;
325. char pname[100];
326.
327. system("cls");
328.
329. do
330. {
331. system("cls");
332. cout << "######## Hotel Management #########\n";
333. cout << "\n1. Manage Rooms";
334. cout << "\n2. Check-In Room";
335. cout << "\n3. Available Rooms";
336. cout << "\n4. Search Customer";
337. cout << "\n5. Check-Out Room";
338. cout << "\n6. Guest Summary Report";
339. cout << "\n7. Exit";
340. cout << "\n\nEnter Option: ";
341. cin >> opt;
342. switch (opt)
343. {
344. case 1:
345. manageRooms();
346. break;
347. case 2:
348. if (count == 0)
349. {
350. cout << "\nRooms data is not available.\nPlease add the rooms first.";
351. getch();
352. }
353. else
354. hm.checkIn();
355. break;
356. case 3:
357. if (count == 0)
358. {
359. cout << "\nRooms data is not available.\nPlease add the rooms first.";
360. getch();
361. }
362. else
363. hm.getAvailRoom();
364. break;
365. case 4:
366. if (count == 0)
367. {
368. cout << "\nRooms are not available.\nPlease add the rooms first.";
369. getch();
370. }
371. else
372. {
373. cout << "Enter Customer Name: ";
374. cin >> pname;
375. hm.searchCustomer(pname);
376. }
377. break;
378. case 5:
379. if (count == 0)
380. {
381. cout << "\nRooms are not available.\nPlease add the rooms first.";
382. getch();
383. }
384. else
385. {
386. cout << "Enter Room Number : ";
387. cin >> rno;
388. hm.checkOut(rno);
389. }
390. break;
391. case 6:
392. hm.guestSummaryReport();
393. break;
394. case 7:
395. cout << "\nTHANK YOU! FOR USING SOFTWARE";
396. break;
397. default:
398. cout << "\nPlease Enter correct option";
399. break;
400. }
401. } while (opt != 7);
402.
403. getch();
404. }
Output:
Enter Option: 2
Enter room number: 1
Room Details
Room is available
Room Number: 1
Type AC/Non-AC (A/N) A
Type Comfort (S/N) S
Type Size (B/S) B
Rent: 1000
//when option 2 check in room
Enter Phone: 456378654
Enter From Date: 30/07/2022
Enter to Date: 02/08/2022
Enter Advance Payment: 500
Customer Checked-in Successfully..
//when search for customer
Enter Option: 4
Enter Customer Name: Rohit
Customer Name: Rohit
Room Number: 1
Press enter for next record
//when option chosen for check out
Enter Option: 5
Enter Room Number : 1
Enter Number of Days: 10
//DEVELOPED BY G. Rohit
//C++ PROJECT
#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include<dos.h>
//START OF CLASS
class hotel
{
int room_no;
char name[30];
char address[50];
char phone[10];
public:
void hotel::main_menu()
{
int choice;
while(choice!=5)
{
system("cls");
cout<<"\n\t\t\t\t*************************";
cout<<"\n\t\t\t\t SIMPLE HOTEL MANAGEMENT ";
cout<<"\n\t\t\t\t * MAIN MENU *";
cout<<"\n\t\t\t\t*************************";
cout<<"\n\n\n\t\t\t1.Book A Room";
cout<<"\n\t\t\t2.Customer Records";
cout<<"\n\t\t\t3.Rooms Allotted";
cout<<"\n\t\t\t4.Edit Record";
cout<<"\n\t\t\t5.Exit";
cout<<"\n\n\t\t\tEnter Your Choice: ";
cin>>choice;
switch(choice)
{
case 1: add();
break;
case 2: display();
break;
case 3: rooms();
break;
case 4: edit();
break;
case 5: break;
default:
{
cout<<"\n\n\t\t\tWrong choice.....!!!";
cout<<"\n\t\t\tPress any key to continue....!!";
getch();
system("cls");
int r,flag;
ofstream fout("Record.dat",ios::app);
flag=check(r);
if(flag)
cout<<"\n Sorry..!!!Room is already booked";
else
{
room_no=r;
cout<<" Name: ";
cin>>name;
cout<<" Address: ";
cin>>address;
cout<<" Phone No: ";
cin>>phone;
fout.write((char*)this,sizeof(hotel));
cout<<"\n Room is booked...!!!";
getch();
fout.close();
void hotel::display()
{
system("cls");
ifstream fin("Record.dat",ios::in);
int r,flag;
while(!fin.eof())
{
fin.read((char*)this,sizeof(hotel));
if(room_no==r)
{
system("cls");
cout<<"\n Cusromer Details";
cout<<"\n ----------------";
cout<<"\n\n Room no: "<<room_no;
cout<<"\n Name: "<<name;
cout<<"\n Address: "<<address;
cout<<"\n Phone no: "<<phone;
flag=1;
break;
if(flag==0)
cout<<"\n Sorry Room no. not found or vacant....!!";
cout<<"\n\n Press any key to continue....!!";
getch();
fin.close();
}
void hotel::rooms()
{
system("cls");
ifstream fin("Record.dat",ios::in);
cout<<"\n\t\t\t List Of Rooms Allotted";
cout<<"\n\t\t\t ----------------------";
cout<<"\n\n Room No.\tName\t\tAddress\t\t\t\tPhone No.\n";
while(!fin.eof())
{
fin.read((char*)this,sizeof(hotel));
cout<<"\n\n "<<room_no<<"\t\t"<<name;
cout<<"\t\t"<<address<<"\t\t"<<phone;
system("cls");
int choice,r;
cout<<"\n EDIT MENU";
cout<<"\n ---------";
cout<<"\n\n 1.Modify Customer Record";
cout<<"\n 2.Delete Customer Record";
cout<<"\n 3. Bill Of Customer";
cout<<"\n Enter your choice: ";
cin>>choice;
system("cls");
switch(choice)
{
case 1: modify(r);
break;
case 2: delete_rec(r);
break;
case 3: bill(r);
break;
}
cout<<"\n Press any key to continue....!!!";
getch();
}
int hotel::check(int r)
{
int flag=0;
ifstream fin("Record.dat",ios::in);
while(!fin.eof())
{
fin.read((char*)this,sizeof(hotel));
if(room_no==r)
{
flag=1;
break;
fin.close();
return(flag);
}
void hotel::modify(int r)
{
long pos,flag=0;
fstream file("Record.dat",ios::in|ios::out|ios::binary);
while(!file.eof())
{
pos=file.tellg();
file.read((char*)this,sizeof(hotel));
if(room_no==r)
{
if(flag==0)
cout<<"\n Sorry Room no. not found or vacant...!!";
file.close();
void hotel::delete_rec(int r)
{
int flag=0;
char ch;
ifstream fin("Record.dat",ios::in);
ofstream fout("temp.dat",ios::out);
while(!fin.eof())
{
fin.read((char*)this,sizeof(hotel));
if(room_no==r)
if(ch=='n')
fout.write((char*)this,sizeof(hotel));
flag=1;
else
fout.write((char*)this,sizeof(hotel));
fin.close();
fout.close();
if(flag==0)
cout<<"\n Sorry room no. not found or vacant...!!";
else
{
remove("Record.dat");
rename("temp.dat","Record.dat");
void hotel::bill(int r)
{
hotel h1;
ifstream f1;
f1.open("record.dat",ios::in|ios::binary);
if(!f1)
cout<<"cannot open";
else
{
f1.read((char*)&h1,sizeof (hotel));
while(f1)
f1.read((char*)&h1,sizeof(hotel));
}
if (h1.room_no == r)
{
if(h1.room_no>=1&&h1.room_no<=30)
cout<<"your bill = 2000";
else if (h1.room_no>=35&&h1.room_no<=45)
cout<<"your bill = 5000" ;
else
cout<<"your bill = 7000";
else
{ cout<<"room no. not found";}
f1.close();
getch();
int main()
{
hotel h;
system("cls");
cout<<"\n\t\t\t****************************";
cout<<"\n\t\t\t* HOTEL MANAGEMENT PROJECT *";
cout<<"\n\t\t\t****************************";
cout<<"\n\n\t\tDeveloped By:";
cout<<"\t G. Rohit";
cout<<"\n\n\n\n\n\n\n\t\t\t\t\tPress any key to continue....!!";
getch();
h.main_menu();
return 0;
}