Answer: Provided in the explanation segment
Step-by-step explanation:
The code below is provided to run this problem and solve this problem.
Code:
#include<stdio.h> //for printf and scanf
#include<stdbool.h> //for boolean datatype
char seats[13][6]; //2d char array represents seats of the airplane
//menu function prints the menu
void menu(){
printf("1) Display seats\\2) Reserve a seat\\Enter option: ");
}
//displayMap function prints the seat occupancies
void displayMap(){
int i,j;
printf("\\* - available\\X - occupied\\");
printf(" A B C D E F\\");
for(i=0;i<13;i++){
printf("%2d ",i+1);
for(j=0;j<6;j++){
printf("%c ",seats[i][j]);
}
printf("\\");
}
}
//validate returns true if seat is available, else returns false
bool validate(char c, int r)r<1
//prompts user to enter seat no. then validates and reserves the seat
void makeReservation(){
char s[3],col;
int row = 0, i=1;
printf("Enter seat number (eg: A1 or C12): ");
scanf("%s",s);
col = s[0];
while(i<3&&s[i]!='\0'){
row = row*10 + (int)(s[i]-'0');
i += 1;
}
if(validate(col,row)){
seats[row-1][col-'A'] = 'X';
printf("%c%d is reserved for You. Thank you.",col,row);
}
else printf("%c%d reservation failed. Please check seat no. & try again!!",col,row);
}
//main function
int main()
{
int i,j,option;
//loops through the char array and assigns * to represent the seats are available
for(i=0;i<13;i++){
for(j=0;j<6;j++){
seats[i][j] = '*';
}
}
do{ //loop continues until user enters neither 1 nor 2
menu(); //calls menu function
scanf("%d",&option);
if(option==1){ //if option is 1 then displayMap function is called
displayMap();
}
else if(option==2){ //if option entered is 2 then makeReservation function gets called
makeReservation();
}
printf("\\\\");
}while(option==1||option==2);
printf("Thank you for using our service\\");
return 0;
}
Cheers i hope this helped !!