Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to assign passengers seats in an airplane. Assume a small airpla

ID: 3775393 • Letter: W

Question

Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as follows: 1ABC D 2ABC D 3ABC D 4ABC D 5ABC D 6ABC D 7ABC D The program should display the seat pattern, with an X marking the seats already assigned, for example, after seats 1A, 2B. and 4C are taken, the display should look like this: 1XBC D 2AXC D 3ABC D 4ABXD 5ABC D 6ABC D 7ABC D After displaying the seats available, the program prompts for the seat desired, the user types in a seat, and then the display of available seats is updated. This continues until all seats are filled or until the user signals that die program should end. If the user types in a seat that is already assigned, the program should say that that seat is occupied and ask for another choice

Explanation / Answer

#include<stdio.h>


void printSeats(char a[7][4]){
   int i=1,j=1;
   for(i=0;i<7;i++){
       printf(" %d",i+1);
       for(j=0;j<4;j++)
           printf("%c ",a[i][j]);
   }
}


void main(){
   char seats[7][4];
   int i,j,n,flag=0, count=0;;
   char ch = 'Y';
   char s1 = 'A';
   for(i=0;i<7;i++){
       seats[i][0]='A';
       seats[i][1]='B';
       seats[i][2]='C';
       seats[i][3]='D';
   }


   printSeats(seats);


   while(ch!='N' && ch!='n' && count<28){
       flag = 0;
       while(flag == 0){
       printf(" Enter seat row(1-7):");
       scanf("%d",&n);
       fflush(stdin);
       printf(" Enter seat number(A/B/C/D):");
      
       fflush(stdin);
       getchar();
       s1 = getchar();
       if(s1 == 'A') j = 0;
       if(s1 == 'B') j = 1;
       if(s1 == 'C') j = 2;
       if(s1 == 'D') j = 3;
       if(seats[n-1][j] == 'X'){
           printf(" Seat is already taken. Please re-enter");
       }
       else{
           flag = 1;
           printf("Seat is assigned");
           seats[n-1][j] = 'X';
           count++;
       }
       }
       printSeats(seats);
       printf(" Do you want to continue? ");
       fflush(stdin);
       getchar();
       ch = getchar();
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote