Hotel Management System in Simple C language

Hotel Management System in Simple C language

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#define size 51

void mainm(void);
void entry(void);
void modify(void);
void delet(void);
void view(void);

// Structure

struct hoteldata
{
char name[size][30], nic[size][20],rdate[size][12],cdate[size][12];
};

struct hoteldata guest;

struct hoteldata1
{
char name[size][30], nic[size][20],rdate[size][12],cdate[size][12];
};

struct hoteldata1 guest1;

// Initializations

int li,lp,sr[size];int dr[size];int rno;int i;int e;
char rc,ch,choice,echoice,rchoice,temp[80],vchoice,mf,ar;
// Main Fuction
void main(void)
{
clrscr();
sr[0]=1;dr[0]=1; // THE MAIN LOGIC !!

for(li=10;li<71;li++)
{
gotoxy(li,15);
delay(30);
printf("/");
}
for(li=70;li>=10;li--)
{
gotoxy(li,22);
delay(30);
printf("\");
}
for(lp=16;lp<=21;lp++)
{
gotoxy(10,lp);
delay(100);
printf("-");
}
for(lp=21;lp>=16;lp--)
{
gotoxy(70,lp);
delay(100);
printf("=");
}
gotoxy(16,17);
textcolor(BLINK + MAGENTA);
cprintf("Welcome To The UMER MAXUD's Hotel Reservation System");
gotoxy(12,20);
cprintf("Designed By UMER MAXUD'S Technologies (C) 2011-2012");
gotoxy(36,28);
textcolor(LIGHTGREEN);
cprintf("Coded By");
gotoxy(24,31);
textcolor(2);
cprintf(" U M E R M A X U D");
gotoxy(26,34);
textcolor(3);
cprintf("S P 1 1 - B C S - 1 6 5");
textcolor(4);
gotoxy(22,37);
cprintf("COMPUTER SCIENCES DEPARTMENT");
textcolor(5);
gotoxy(25,40);
textcolor(6);
cprintf("www.facebook.com/Thin.kiing");
gotoxy(44,48);
textcolor(WHITE);
cprintf("Press Any Key To ..........Continue");
getch();
mainm();
}// Main Fuction End

//Main Menu Function
void mainm(void)
{
clrscr();
for(li=30;li<=50;li++)
{
gotoxy(li,14);
delay(30);
printf("*");
}
for(li=50;li>=30;li--)
{
gotoxy(li,30);
delay(30);
printf("*");
}
for(lp=15;lp<30;lp++)
{
gotoxy(30,lp);
delay(100);
printf("|");
}
for(lp=29;lp>=15;lp--)
{
gotoxy(50,lp);
delay(100);
printf("|");
}
gotoxy(15,10);
textcolor(LIGHTGRAY);
cprintf("Press the corresponding Keys for the desired action");
gotoxy(33,16);
textcolor(BROWN);
cprintf("R: Reservation");
gotoxy(33,19);
textcolor(LIGHTMAGENTA);
cprintf("V: Room Status");
gotoxy(33,22);
textcolor(LIGHTBLUE);
cprintf("M: Modification");
gotoxy(33,25);
textcolor(LIGHTRED);
cprintf("D: Deletion");
gotoxy(33,28);
textcolor(GREEN);
cprintf("Q: Quit");
textcolor(WHITE);
choice=getch();
switch(choice)
{// Choice Switch Begin
case 'R':
entry();
case 'V':
view();
case 'M':
modify();
case 'D':
delet();
case 'Q':
exit(0);
default:
{//Choice Default
gotoxy(33,40);
printf("nnIllegal Choice or make sure CAPS Lock is on");
getch();
mainm();

}//Choice Default End
} //Choice Switch End
} //Main Menu Function End

// Data Entry Function
void entry(void)
{//Data Entry Function Begin
clrscr();
printf("Do You Want To reserve A Room? (Y/N)n");
echoice=getch();
switch(echoice) // Echoice Switch Begin
{
case 'Y':
{ // E-Choice Case Y Begin
printf("nnEnter S for Single Room or D for Double Roomnn");
rchoice=getch();
switch(rchoice) // Rchoice Switch Begin
{
case 'S': // Rchoice
{// R-Choice Case S Begin
for(i=1;i<size;i++)
if(sr[i]==0)
{// Single Room IF begin
clrscr();
sr[i]=1;
printf("nnRoom No : %d Is available For Reservation",i);
printf("nnEnter Occupant's Namen");
gets(guest.name[i]);
printf("nnEnter Occupant's NIC Numbern");
gets(guest.nic[i]);
printf("nnEnter Check In Daten");
gets(guest.rdate[i]);
printf("nnEnter Check Out Daten");
gets(guest.cdate[i]);
printf("nnnnDo You Want To Reserve Another Room? Y/N");
ar=getch();
switch (ar)
{// AR Switch Begin
case 'Y':
entry();
case 'N':
mainm();
default:
{//AR Default Begin
printf("nnIllegal Choice or make sure CAPS Lock is on");
getch();
mainm();
}//AR Default End

}// AR Switch End
}// Single Room IF End
}// Rchoice Case S End

case 'D':
{ //Rchoice Case D Begin
for(i=1;i<size;i++)
if(dr[i]==0)
{// Double Room IF begin
clrscr();
dr[i]=1;
printf("nnRoom No : %d Is available For Reservation",i);
printf("nnEnter Occupant's Namen");
gets(guest1.name[i]);
printf("nnEnter Occupant's NIC Numbern");
gets(guest1.nic[i]);
printf("nnEnter Check In Daten");
gets(guest1.rdate[i]);
printf("nnEnter Check Out Daten");
gets(guest1.cdate[i]);
printf("nnnnDo You Want To Reserve Another Room? Y/N");
ar=getch();
switch (ar)
{// AR Switch Begin
case 'Y':
entry();
case 'N':
mainm();
default:
{//AR Default Begin
printf("nnIllegal Choice or make sure CAPS Lock is on");
getch();
mainm();
}//AR Default End
}// AR Switch End
}// Double Room IF End
}// Rchoice Case D End
default: // Rchoice Default
{//Rchoice Default Begin
printf("nnIllegal Choice or make sure CAPS Lock is on");
getch();
mainm();
}//Rchoice default end
}//Rchoice End
}//Echoice Case Y End
case 'N':
{// Echoice Case N Begin
mainm();
}//Echoice Case N End
default: //Echoice Default
printf("nnIllegal Choice or make sure CAPS Lock is on");
getch();
mainm();
} // Echoice Default End
} //Data Entry Function End
// Data View Fucntion
void view(void)
{// Data View Function Begin
clrscr();
printf("Press S for Sequential Display of the room status 
nnPress R for Manual Check Of Room Statusnn");
vchoice=getch();
switch(vchoice)
{//Vchoice Switch Begin
case 'S':
{//Vchoice Case S Begin
clrscr();
printf("R.No.tNamettNIC NumbertCheck IntCheck Outn");
for(i=1;i<size;i++)
{//i Loop Begin
if(sr[i]==1)
{//SR[i]==1 Conditional Printing Begin
printf("n%dt%st%st%st%sn",i,guest.name[i],guest.nic[i], 
guest.rdate[i],guest.cdate[i]);

}//SR[i]==1 Conditional Printing End
}//i Loop End
printf("nnnPress Any Key For Double Room Statusnn");
getch();
clrscr();
printf("R.No.tNamettNIC NumbertCheck IntCheck Outn");
for(i=1;i<size;i++)
{//i Loop Begin
if(dr[i]==1)
{//dr[i]==1 Conditional Printing Begin
printf("n%dt%st%st%st%sn",i,guest1.name[i],guest1.nic[i] 
,guest1.rdate[i],guest1.cdate[i]);

}//dr[i]==1 Conditional Printing End
}//i Loop End
printf("nnnPress Any Key To Return To The Main Menunn");
getch();
mainm();
}//Vchoice Case S End
case 'R':
{// Vchoice case R Start
clrscr();
printf("Enter The Room Number That Needs To Be Checked For 
Occupancynn");
gets(temp);
rno=atoi(temp);
// Room Number Limit Check
if(rno<1 || rno >51)
{//IF Condition Begin
printf("nnIllegal Room Number");
getch();
mainm();
} //IF Condition End
else
{ // Limit Else Falsified Begin
if(sr[rno]==1)
{//sr==1 if Begin
printf("nnSingle Room No %d Is Reserved",rno);
printf("nnOccupant's Name : %s nnOccupant's NIC Number : %s nnnCheck In Date : %snnCheck Out Date : %s nn", guest.name[rno],guest.nic[rno],guest.rdate[rno],guest.cdate[rno]);
}//sr==1 if End
else
{// sr else begin
printf("nnSingle Room No %d is Vacant",rno);
getch();
}//sr else end
if(dr[rno]==1)
{//dr==1 if Begin
printf("nnDouble Room No %d Is Reserved",rno);
printf("nOccupant's Name : %s nnOccupant's NIC Number : %s nnCheck In Date : %snnCheck Out Date : %s nn", guest1.name[rno],guest1.nic[rno],guest1.rdate[rno],guest1.cdate[rno]);
printf("nnPress Any Key To Return To The Main Menu");
getch();
mainm();
}//dr==1 if End
else
{// dr else begin
printf("nnDouble Room No %d is Vacant",rno);
getch();
mainm();
}//dr else end
}//Vchoice Case R End
}// Falsified Limit End
default:
{
//Vchoice Default Begin
printf("nnIllegal Choice or make sure CAPS Lock is on");
getch();
mainm();
} // Vchoice Default End
} // Vchoice Switch End
} // Data View Function End

//Modify Function
void modify(void)
{// Modify Function Begin
clrscr();
printf("ttttData Modificationnnnnnn");
printf("Enter The Room Number To Be Modifiedn");
gets(temp);
rno=atoi(temp);
// Room Number Limit Check
if(rno<1 || rno >51)
{//IF Condition Begin
printf("nnIllegal Room Number");
getch();
mainm();
} //IF Condition End
else
{ // Limit Else Falsified Begin
printf("Enter S For Single Room / D For Double Roomn");
rc=getch();
switch(rc)
{//rc Switch Begin
case 'S':
{//rc Case S Begin
if(sr[rno]==1)
{//sr==1 if Begin
clrscr();
printf("nnSingle Room No %d Is Reserved",rno);
printf("nnOccupant's Name : %s nnOccupant's NIC Number : 
%s nnCheck In Date : %snnCheck Out Date : %s nn", 
guest.name[rno],guest.nic[rno],guest.rdate[rno],guest.cdate[rno]);

printf("nnPress N : Change Of NamenI : Change In NICnR : 
Check In DatenO : Check Out Datenn");
mf=getch();
switch(mf)
{//mf switch Begin
case 'N':
{//mf Case N Begin
printf("nnEnter New Namen");
gets(guest.name[rno]);
getch();
mainm();
}//mf Case N End
case 'I':
{//mf Case I Begin
printf("nnEnter New NIC Numbern");
gets(guest.nic[rno]);
getch();
mainm();
}//mf Case I End
case 'R':
{//mf Case R Begin
printf("nnEnter New Check In Daten");
gets(guest.rdate[rno]);
getch();
mainm();
}//mf Case R End
case 'O':
{//mf Case O Begin
printf("nnEnter New Check Out Daten");
gets(guest.cdate[rno]);
getch();
mainm();
}//mf Case O End
default:
{//mf Default Begin
printf("nnInvalid Entry");
getch();
mainm();
}//mf Default End
}//sr==1 if End
} //rc Case S End
else
{// sr else begin
printf("nnSingle Room No %d is Vacant",rno);
getch();
mainm();
}//sr else end
}//rc Case S End
case 'D':
{// rc Case D Begin
if(dr[rno]==1)
{//dr==1 if Begin
clrscr();
printf("nnDouble Room No %d Is Reserved",rno);
printf("nnOccupant's Name : %s nnOccupant's NIC Number : 
%s nnCheck In Date : %snnCheck Out Date : %s nn",
guest1.name[rno],guest1.nic[rno],guest1.rdate[rno],
guest1.cdate[rno]);

printf("nnPress N : Change Of NamenI : Change 
In NICnR : Check In DatenO : Check Out Datenn");
mf=getch();
switch(mf)
{//mf switch Begin
case 'N':
{//mf Case N Begin
printf("nnEnter New Namen");
gets(guest1.name[rno]);
getch();
mainm();
}//mf Case N End
case 'I':
{//mf Case I Begin
printf("nnEnter New NIC Numbern");
gets(guest1.nic[rno]);
getch();
mainm();
}//mf Case I End
case 'R':
{//mf Case R Begin
printf("nnEnter New Check In Daten");
gets(guest1.rdate[rno]);
getch();
mainm();
}//mf Case R End
case 'O':
{//mf Case O Begin
printf("nnEnter New Check Out Daten");
gets(guest1.cdate[rno]);
getch();
mainm();
}//mf Case O End
default:
{//mf Default Begin
printf("nnIllegal Choice or make sure CAPS Lock is on");
getch();
mainm();
}//mf Default End
}//dr==1 if End
}//rc Case D End
else
{// dr else begin
printf("nnSingle Room No %d is Vacant",rno);
getch();
mainm();
}//dr else end
} // Case D End
default:
{// rc Default Begin
printf("nnnIllegal Entry Or Make Sure CAPS Lock is On");
getch();
mainm();
} // rc Default End
} //Switch rc End
} // Limit Else Falsified End
} //Modify Function End
//Delete Function
void delet(void)
{//Delete Function
clrscr();
printf("Enter The Room Number To Vacaten");
gets(temp);
rno=atoi(temp);

// Room Number Limit Check
if(rno<1 || rno >51)
{//IF Condition Begin
printf("nnIllegal Room Number");
getch();
mainm();
} //IF Condition End
else
{// Room Number Limit Falsified Else
printf("nnSingle Or Double Room? (S/D)");
rc=getch();
switch(rc)
{//rc Switch Begin
case 'S':
{//rc Case S Begin
sr[rno]=0;
printf("nnRoom Vacated");
printf("nnPress Any Key To Exit To The Main Menu");
getch();
mainm();
}// rc Case S End
case 'D':
{//rc Case D Begin
dr[rno]=0;
printf("nnRoom Vacated");
printf("nnPress Any Key To Exit To The Main Menu");
getch();
mainm();
}//rc Case D End
default:
{//rc Default Begin
printf("nnIllegal Choice Or Make Sure CAPS Lock is ON");
getch();
mainm();
}// rc Default End
}// rc Switch End
}// Room Number Falsified Else End
}// Delete Function End

// END OF PROGRAM

Let's Discuss

  • umar

    Really helpfull
    keep sharing more articles related to programming

  • john

    Thanks for sharing your code

  • EE-raj Kanwal Eye-k

    can any one plz tell that how to read and write file in the above given program..

    • Bisma

      no 😛