C Programming Question (must use the language C and an IDE such as Codeblocks) W
ID: 3914003 • Letter: C
Question
C Programming Question (must use the language C and an IDE such as Codeblocks)
Write a hotel reservation system (Res system) that will enable guest to check-in and check-out from the hotel. The reservation system needs to have a structure to keep track of room availability in a hotel.
Specifications:
1- The hotel must have 10 rooms, each assigned a room number from 1 to 10.
2- The res system should keep track of the the rooms and if no rooms available, notify the user that the hotel is full.
3- When a guest checks out the room should be returned to the pool of available rooms.
2- The Res system must ask and provide the user with the following questions/options and call a function for each option to complete the choice entered by the user. The options are:
Would you like:
1) To check in (enter: 1)
2) To check out (enter 2)
3) To print availability (enter: 3)
4) To quit (enter: 4)
In addition, add to the Res system so that in its struct it should store how many people are staying in each room. That is, when asking a party to check in, ask them how many people are in the party, and put all of the people in the party in the next available room. Add a function that calculates the total number of
guests staying at the hotel and add an option to the menu to print out the total number of current guests. The Res system must keep track of the guests as they check-in and check-out.
Explanation / Answer
#include<stdio.h>
#include<stdbool.h>
struct room{
bool available;
int no_of_person;
};
int main(){
struct room r[10];
int i,choice,people,room_number,sum=0;
for( i=0;i<10;i++){
r[i].available=true;
r[i].no_of_person=0;
}
do{
printf(" 1:check in 2:check out 3:check availability 4:Total number of current guesta 5:quit ");
scanf("%d",&choice);
switch(choice){
case 1:{
printf("Enter number of person : ");
scanf("%d",&people);
for(i=0;i<10;i++){
if(r[i].available){
printf("Room number %d is alloted ",i+1);
r[i].available=false;
r[i].no_of_person=people;
break;
}
if(i==10)printf("Hotel is full ");
}
break;
}
case 2:{
printf("Enter room number going to vacate : ");
scanf("%d",&room_number);
if(room_number>10||room_number<1)printf("Invalid room number ");
else if(r[room_number-1].available==true)printf("Room number %d is not alloted. ",room_number);
else{
r[room_number-1].available=false;
r[room_number-1].no_of_person=0;
}
break;
}
case 3:{
printf("Enter room number to check availability : ");
scanf("%d",&room_number);
if(r[room_number-1].available)printf("Room number %d is available ",room_number);
else printf("Room number %d is occupied ",room_number);
break;
}
case 4:{
for(i=0;i<10;i++)
sum+=r[i].no_of_person;
printf("Total number of guests in Hotel : %d ",sum);
sum=0;
break;
}
case 5:{
printf("Thank you ");
break;
}
}
}while(choice!=5);
return 0;
}
for any query please comment
please upvote if find it helpful
Thank you!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.