Programming / Computing

Hotel Management

 This is a project which imitates Hotel management and this project is fully menu based program and it will work according to the input provided to it

..............................................................................................................................................................................

 

 

 

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<process.h>

#include<dos.h>

#include<ctype.h>

 

/* Structure to store data which is read from the file

and to store data prior to its storage in the file */

 

struct HOTEL

{

int roomno;

char name[18];

char phoneno[10];

char roomtype;

int roomstatus;

int cindate;

}hot;

 

void main()

{

FILE *fp;

int mchoice,schoice;

char another = 'y';

int flag = 0;

int rno;

int recsize;

int rnum,days;

int num;

struct date d;

char temp[sizeof(hot.name)] = "";

int price_d = 5000, price_n = 3000;

 

fp = fopen("project.txt","rb+");

getdate(&d);

 

if(fp == NULL)

{

puts("cannot open file");

exit(1);

}

 

recsize = sizeof(hot);

 

/* This loop exexutes till the user inputs a character other

than 'y' so that user can execute the program from the main menu

as many times as he may like */

 

while(tolower(another) == 'y')

{

/* This is used to display the main menu on the screen */

 

clrscr();

//gotoxy(30,8);

printf("BY : Vishaldeep Singh");

gotoxy(30,10);

printf("WELCOME TO HOTEL RADDISON");

gotoxy(30,12);

printf("1. search");

gotoxy(30,14);

printf("2. check in");

gotoxy(30,16);

printf("3. check out");

gotoxy(30,18);

printf("4. room status");

gotoxy(30,20);

printf("5. exit");

gotoxy(30,22);

printf("ENTER YOUR CHOICE: ");

 

fflush(stdin);

 

scanf("%d",&mchoice);

 

switch(mchoice)

{

/* This will be executed when user wants to search in a person who has already checked in

He may do so either by name or by room number */

 

case 1:

printf("select from the following\ndo you want to search by\n1 for name wise\n2 for room wise\nenter your choice  ");

scanf("%d",&schoice);

 

switch(schoice)

{

/* Searching by name */

case 1:

printf("enter the name  ");

//gets(temp);

scanf("%s",temp);

rewind(fp);

flag = 0;

while(fread(&hot,recsize,1,fp) != 0)

{

if(strcmp(hot.name,temp) == 0)

{

printf("\nthe details of the person are:\n\n\n");

printf("name is %s\nphone no. is %s\nroom no. is %d\ncheck in date is %d\n",hot.name,hot.phoneno,hot.roomno,hot.cindate);

flag = 1;

break;

}

}

if(flag != 1)

printf("incorrect name. this person have not checked in\n");

 

break;

 

/* Searching by room number */

case 2:

printf("enter the room number  ");

scanf("%d",&num);

rewind(fp);

while(fread(&hot,recsize,1,fp) != 0)

{

if(num == hot.roomno)

{

if(hot.roomstatus != 0)

{

printf("\nthe details of the room are:\n\n\n");

printf("name is %s\nphone no. is %s\nroom no. is %d\ncheck in date is %d\n",hot.name,hot.phoneno,hot.roomno,hot.cindate);

}

else

printf("the room is not booked\n");

 

break;

}

 

}

break;

 

default:

printf("inappropriate chioce selection\n");

break;

}

break;

 

/* This part of code will check in a person who will be given 2 choices

for a deluxe or a non deluxe room */

case 2:

printf("select from the following\n1 for deluxe\n2 for semi deluxe\nenter your choice  ");

scanf("%d",&schoice);

 

switch(schoice)

{

/* checks the availability of the deluxe room and if possible

books the room for the customer */

case 1:

rewind(fp);

flag = 0;

while(fread(&hot,recsize,1,fp) != 0)

{

if (hot.roomno <= 100 && hot.roomno>=61 && hot.roomstatus == 0)

{

printf("room is available\n");

rno = hot.roomno;

flag = 1;

break;

}

}

if(flag != 1)

printf("soory room is not available\n");

else

{

printf("enter your name ");

scanf("%s",hot.name);

printf("enter your phone no. ");

scanf("%s",hot.phoneno);

hot.roomstatus = 1;

hot.cindate = d.da_day;

hot.roomtype = 'd';

hot.roomno = rno;

fseek(fp,-recsize,SEEK_CUR);

fwrite(&hot,recsize,1,fp);

printf("CONGRATS YOUR ROOM HAS BEEN BOOKED\n");

printf("your room no. is %d\n",hot.roomno);

}

break;

 

/* checks the availability of the non-deluxe room and if possible

books the room for the customer */

case 2:

rewind(fp);

flag = 0;

while(fread(&hot,recsize,1,fp) != 0)

{

if (hot.roomno <= 60 && hot.roomno >= 1 && hot.roomstatus == 0)

{

printf("room is available\n");

flag = 1;

rno = hot.roomno;

break;

}

}

 

if(hot.roomstatus == 1)

printf("soory room is not available\n");

else

{

printf("enter your name ");

scanf("%s",hot.name);

printf("enter your phone no. ");

scanf("%s",hot.phoneno);

hot.roomstatus = 1;

hot.cindate = d.da_day;

hot.roomtype = 'n';

hot.roomno = rno;

fseek(fp,-recsize,SEEK_CUR);

fwrite(&hot,recsize,1,fp);

printf("CONGRATS YOUR ROOM HAS BEEN BOOKED\n");

printf("your room no. is %d\n",hot.roomno);

}

break;

 

default:

printf("Inappropriate choice selection");

break;

 

}

break;

 

/* Checks out a person and calculates the total bill for the person */

case 3:

printf("enter your room number  ");

fflush(stdin);

scanf("%d",&rnum);

 

rewind(fp);

while(fread(&hot,recsize,1,fp) != 0)

{

if(hot.roomno == rnum)

{

if(hot.roomstatus != 0)

{

/* To ensure that the person has not entered some wrong room number */

 

printf("are you %s\n",hot.name);

printf("enter 1 for YES\n or 2 for NO  ");

fflush(stdin);

scanf("%d",&schoice);

switch(schoice)

{

case 2:

printf("please follow the procedure again\n");

//continue;

break;

 

case 1:

days = d.da_day - hot.cindate;

 

if(tolower(hot.roomtype) == 'd')

printf("the total bill is = %d\n",3000 + days*price_d);

else //if(tolower(hot.roomtype) == 'n');

printf("the total bill is = %d\n",1000 + days*price_n);

 

strcpy(hot.name,"");

strcpy(hot.phoneno,"");

hot.roomstatus = 0;

fseek(fp,-recsize,SEEK_CUR);

fwrite(&hot,recsize,1,fp);

printf("SUCCESSFULLY CHECKED OUT");

fclose(fp);

fopen("project.txt","rb+");

break;

 

default:

printf("inappropriate chioce selected\n");

}

}

else

printf("this room is empty\n");

 

break;

}

}

break;

 

/* To check the status of a room i.e. to know that whether a room is booked or available */

case 4:

printf("enter the room number  ");

fflush(stdin);

scanf("%d",&rnum);

flag = 0;

rewind(fp);

while(fread(&hot,recsize,1,fp) != 0)

{

if(hot.roomno == rnum)

{

if(hot.roomstatus == 0)

printf("the room is not booked\n");

else if(hot.roomstatus == 1)

{

printf("the room is already booked\n");

//break;

}

flag = 1;

break;

}

}

if(flag == 0)

printf("invalid room number\n");

 

break;

 

/* To exit from the program execution */

case 5:

fclose(fp);

exit(0);

break;

 

/* To ensure that person has not entered a wrong value when choosing from the main menu */

default:

printf("inappropriate choice selected\n");

break;

}

 

/* To know whether or not user wants to execute the program again */

printf("\n\nwant to execute again\n");

printf("enter Y or N  ");

fflush(stdin);

scanf("%c",&another);

}

}

© 2010 All rights reserved.

Make a free websiteWebnode