Project Hotel Room Reservation Program in C++

This is the code of hotel management system.

#include<iostream.h>

#include<stdio.h>

#include<dos.h>

#include<string.h>

#include<conio.h>

#define max 100

/*———————-

Class Person:

Inner Class (Nested Class) for Class Room

———————-*/

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 (Input A/N): “;

cin>>room.ac;

cout<<”nType Comfort (Input N/D/L): “;

cin>>room.type;

cout<<”nType Size (S/D): “;

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<<”n——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 (Input A/N): “<<tempRoom.ac;

cout<<”nType Comfort (Input N/D/L): “<<tempRoom.type;

cout<<”nType Size (S/D): “<<tempRoom.stype;

cout<<”nRent: “<<tempRoom.rent;

}

class HotelMgnt:protected Room

{

public:

void reserveRoom();

void getAvailRoom();

void searchPerson(char *);

void generateBill(int);

};

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 Address: “;

cin>>rooms[i].cust.address;

cout<<”nEnter Customer Phone Number: “;

cin>>rooms[i].cust.phone;

rooms[i].status=1;

}

}

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

}

}

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<<”nAddress: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();

}

}

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<<”nAddress:t”<<rooms[i].cust.address;

cout<<”nPhone:t”<<rooms[i].cust.phone;

//rno = rooms[i].roomNumber;

found=1;

getch();

break;

}

}

if(found==1)

{

cout<<”nnEnter Number of Days:t”;

cin>>days;

billAmount=days * rooms[i].rent;

cout<<”nnTotal Bill Amount:tRs. “<<billAmount<<” /- Only”;

rooms[i].status=0;

}

getch();

}

void manageRooms()

{

class Room room;

int opt,rno,i,flag=0;

char ch;

do

{

clrscr();

cout<<”nn————-Hotel Management————-n”;

cout<<”nn——Manage Room————————-n”;

cout<<”n1. Add Room”;

cout<<”n2. Search Room”;

cout<<”n3. Back to Main Menu”;

cout<<”n———————————————n”;

cout<<”nnEnter Option:t”;

cin>>opt;

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<<”nnPlease Enter correct option”;

break;

}

}while(opt!=3);

}

void main()

{

class HotelMgnt hm;

int i,j,opt,rno;

char ch;

char *pname;

clrscr();

do

{

clrscr();

cout<<”nn————-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<<”n———————————————n”;

cout<<”nnEnter Option:t”;

cin>>opt;

switch(opt)

{

case 1:

manageRooms();

break;

case 2:

if(count==0)

{

cout<<”nRooms data is not available.nKindly add the rooms first.”;

getch();

}

else

hm.reserveRoom();

break;

case 3:

if(count==0)

{

cout<<”nRooms data is not available.nKindly add the rooms first.”;

getch();

}

else

hm.getAvailRoom();

break;

case 4:

if(count==0)

{

cout<<”nRooms data is not available.nKindly 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.nKindly add the rooms first.”;

getch();

}

else

{

cout<<”Enter Room Number: “;

cin>>rno;

hm.generateBill(rno);

}

break;

case 6:

cout<<”nntTHANK YOU…created By Adi007!”;

break;

default:

cout<<”nnPlease Enter correct option”;

break;

}

}while(opt!=6);

getch();

}

bob
11.08.16

nice………..

11.08.16

Very Nice

kenn
11.08.16

hi, could you please classify the superclass and subclass in this coding in terms of java language ? i am just trying to convert this coding into java for better learning. tq =)

nizzer
11.08.16

Hey…The coding and everything is fine but in the class definitions, it’s extremely bad programming to set ur variables as public members. Actually it’s almost like a sin. Example in class Person, u should’ve set the variables, name address and phone; which are pointers to a character, as private member classes then set a function, lets say ‘void name_access(){}’ which will be passing parameters which will help u access the private member set. Don’t think that i’m hating or anything, this is a fabulous job but hey, after all we all learning and sharing knowledge here. Thought maybe i’d point that out to u.

comments powered by Disqus
Loading