0% found this document useful (0 votes)
509 views21 pages

Hotel Management System in C++

This document describes a hotel management system implemented in C++. It includes classes for customers and rooms, and a main class for hotel management functions. The key functions allow users to add rooms, search for available rooms, check customers in and out, and view a guest summary report. Class definitions and function code snippets are provided as examples of how the system is programmed.

Uploaded by

beshahashenafe20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
509 views21 pages

Hotel Management System in C++

This document describes a hotel management system implemented in C++. It includes classes for customers and rooms, and a main class for hotel management functions. The key functions allow users to add rooms, search for available rooms, check customers in and out, and view a guest summary report. Class definitions and function code snippets are provided as examples of how the system is programmed.

Uploaded by

beshahashenafe20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

College of Natural and

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

Submitted to: Ali E.


窗体顶端

ADVERTISEMENT

Hotel Management in C++


This article contains a C++ hotel management project. This system offers a number of choices, like reserving a room, reviewing customer information, changing or removing any client, and seeing
all rooms that have been assigned. Two key C++ concepts-classes and file handling-are used in the project's development.

Features of Hotel Management System in C++


ADVERTISEMENT
ADVERTISEMENT

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.

Backward Skip 10sPlay VideoForward Skip 10s


ADVERTISEMENT

class Room rooms[max];


int count = 0;

We have declared rooms[max] of room class as global and count as 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) : ";
10. cin >> room.stype;
11. cout << "\nDaily Rent : ";
12. cin >> room.rent;
13. room.status = 0;
14. cout << "\n Room Added Successfully!";
15. getch();
16. return room;
17. }

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.

void Room::searchRoom(int rno)


{
int i, found = 0;
for (i = 0; i < count; i++)
{
if (rooms[i].roomNumber == rno)
{
found = 1;
break;
10. }
11. }
12. if (found == 1)
13. {
14. cout << "Room Details\n";
15. if (rooms[i].status == 1)
16. {
17. cout << "\nRoom is Reserved";
18. }
19. else
20. {
21. cout << "\nRoom is available";
22. }
23. displayRoom(rooms[i]);
24. getch();
25. }
26. else
27. {
28. cout << "\nRoom not found";
29. getch();
30. }
31. }

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.

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;
}

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.

class HotelMgnt : protected Room


{
public:
void checkIn();
void getAvailRoom();
void searchCustomer(char *);
void checkOut(int);
void guestSummaryReport();
};

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.

// hotel management reservation of room


void HotelMgnt::checkIn()
{
int i, found = 0, rno;

class Room room;


cout << "\nEnter Room number : ";
cin >> rno;
for (i = 0; i < count; i++)
10. {
11. if (rooms[i].roomNumber == rno)
12. {
13. found = 1;
14. break;
15. }
16. }
17. if (found == 1)
18. {
19. if (rooms[i].status == 1)
20. {
21. cout << "\nRoom is already Booked";
22. getch();
23. return;
24. }
25. cout << "\nEnter booking id: ";
26. cin >> rooms[i].cust.booking_id;
27.
28. cout << "\nEnter Customer Name (First Name): ";
29. cin >> rooms[i].cust.name;
30.
31. cout << "\nEnter Address (only city): ";
32. cin >> rooms[i].cust.address;
33.
34. cout << "\nEnter Phone: ";
35. cin >> rooms[i].cust.phone;
36.
37. cout << "\nEnter From Date: ";
38. cin >> rooms[i].cust.from_date;
39.
40. cout << "\nEnter to Date: ";
41. cin >> rooms[i].cust.to_date;
42.
43. cout << "\nEnter Advance Payment: ";
44. cin >> rooms[i].cust.payment_advance;
45.
46. rooms[i].status = 1;
47.
48. cout << "\n Customer Checked-in Successfully..";
49. getch();
50. }
51. }

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.

// hotel management shows all persons that have booked room


void HotelMgnt::searchCustomer(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: " << rooms[i].cust.name;
10. cout << "\nRoom Number: " << rooms[i].roomNumber;
11.
12. cout << "\n\nPress enter for next record";
13. found = 1;
14. getch();
15. }
16. }
17. if (found == 0)
18. {
19. cout << "\nPerson not found.";
20. getch();
21. }
22. }

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.

// hotel managemt generates the bill of the expenses


void HotelMgnt::checkOut(int roomNum)
{
int i, found = 0, days, rno;
float billAmount = 0;
for (i = 0; i < count; i++)
{
if (rooms[i].status == 1 && rooms[i].roomNumber == roomNum)
{
10. // rno = rooms[i].roomNumber;
11. found = 1;
12. // getch();
13. break;
14. }
15. }
16. if (found == 1)
17. {
18. cout << "\nEnter Number of Days:\t";
19. cin >> days;
20. billAmount = days * rooms[i].rent;
21.
22. cout << "\n\t######## CheckOut Details ########\n";
23. cout << "\nCustomer Name : " << rooms[i].cust.name;
24. cout << "\nRoom Number : " << rooms[i].roomNumber;
25. cout << "\nAddress : " << rooms[i].cust.address;
26. cout << "\nPhone : " << rooms[i].cust.phone;
27. cout << "\nTotal Amount Due : " << billAmount << " /";
28. cout << "\nAdvance Paid: " << rooms[i].cust.payment_advance << " /";
29. cout << "\n*** Total Payable: " << billAmount - rooms[i].cust.payment_advance << "/ only";
30.
31. rooms[i].status = 0;
32. }
33. getch();
34. }

The above peace of code is used to generate the bill of a customer.

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.

Program for Hotel Management System

#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:

######## Hotel Management #########


1. Manage Rooms
2. Check-In Room
3. Available Rooms
4. Search Customer
5. Check-Out Room
6. Guest Summary Report
7. Exit
//when option 1
Enter Option:
### Manage Rooms ###
1. Add Room
2. Search Room
3. Back to Main Menu
Enter Option: 1
Enter Room Number: 1
Type AC/Non-AC (A/N) : A
Type Comfort (S/N) : S
Type Size (B/S) : B
Daily Rent : 1000
Room Added Successfully!
### Manage Rooms ###
1. Add Room
2. Search Room
3. Back to Main Menu

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

######## CheckOut Details ########

Customer Name : Rohit


Room Number : 1
Address : Delhi
Phone : 456378654
Total Amount Due : 10000 /
Advance Paid: 500 /
*** Total Payable: 9500/ only

//DEVELOPED BY G. Rohit

//C++ PROJECT

//START OF THE PROGRAM FOR HOTEL MANAGEMENT

#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include<dos.h>

using namespace std;

//START OF CLASS

class hotel
{

int room_no;
char name[30];
char address[50];
char phone[10];

public:

void main_menu(); //to dispay the main menu


void add(); //to book a room
void display(); //to display the customer record
void rooms(); //to display alloted rooms
void edit(); //to edit the customer record
int check(int); //to check room status
void modify(int); //to modify the record
void delete_rec(int); //to delete the record
void bill(int); //for the bill of a record
};
//END OF CLASS
//FOR DISPLAYING MAIN MENU

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();

//END OF MENU FUNCTION

//FUNCTION FOR BOOKING OF ROOM


void hotel::add()
{

system("cls");
int r,flag;
ofstream fout("Record.dat",ios::app);

cout<<"\n Enter Customer Detalis";


cout<<"\n ----------------------";
cout<<"\n\n Room no: ";
cout<<"\n Total no. of Rooms - 50";
cout<<"\n Ordinary Rooms from 1 - 30";
cout<<"\n Luxuary Rooms from 31 - 45";
cout<<"\n Royal Rooms from 46 - 50";
cout <<"\n Enter The Room no. you want to stay in :- "<<endl;
cin>>r;

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...!!!";

cout<<"\n Press any key to continue.....!!";

getch();
fout.close();

//END OF BOOKING FUNCTION

//FUNCTION FOR DISPLAYING A PURTICULAR CUSTOMER`S RECORD

void hotel::display()
{

system("cls");

ifstream fin("Record.dat",ios::in);
int r,flag;

cout<<"\n Enter room no. for a particular customer`s details :- "<<endl;


cin>>r;

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();
}

//END OF DISPLAY FUNCTION

//FUNCTION TO DISPLAY ALL ROOMS OCCUPIED

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;

cout<<"\n\n\n\t\t\tPress any key to continue.....!!";


getch();
fin.close();

//FUNCTION FOR EDITING RECORDS AND FOR BILL


void hotel::edit()
{

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");

cout<<"\n Enter room no: " ;


cin>>r;

switch(choice)
{

case 1: modify(r);
break;

case 2: delete_rec(r);
break;

case 3: bill(r);
break;

default: cout<<"\n Wrong Choice.....!!";

}
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);
}

//FUNCTION TO MODIFY CUSTOMERS RECORD

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)
{

cout<<"\n Enter New Details";


cout<<"\n -----------------";
cout<<"\n Name: ";
cin>>name;
cout<<" Address: ";
cin>>address;
cout<<" Phone no: ";
cin>>phone;
file.seekg(pos);
file.write((char*)this,sizeof(hotel));
cout<<"\n Record is modified....!!";
flag=1;
break;

if(flag==0)
cout<<"\n Sorry Room no. not found or vacant...!!";
file.close();

//END OF MODIFY FUNCTION

//FUNCTION FOR DELETING RECORD

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)

cout<<"\n Name: "<<name;


cout<<"\n Address: "<<address;
cout<<"\n Pone No: "<<phone;
cout<<"\n\n Do you want to delete this record(y/n): ";
cin>>ch;

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");

//END OF DELETE FUNCTION

//FUNCTION FOR CUSTOMER`S BILL

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();

//END OF BILLING FUNCTION

//START OF MAIN PROGARM

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;
}

//END OF MAIN PROGRAM

You might also like