Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

** C not C++** Complete the program to assign a seat on an airline flight. The user will select First, Business or Economy class. If

** C not C++** Complete the program to assign a seat on an airline flight. The user will select First, Business or Economy class. If there is an available seat, assign it by adding one to the count of the classs seats and displaying a message. If the assignment fills the selected class, display a message that it is now filled. If there are no available seats in the selected class, display a message. The number of available seats in each class are: First 10 Business 15 Economy 25 You must use a switch block to branch to each seat class's assignment code. Within each seat class section, use if else statement to determine if a seat is available, and when there is a seat, use a further if statement to determine if the class is full after assigning the seat. When the user makes a class selection that is not valid (not one of F, B or E, upper or lower case), display an error message. User entries may be upper or lower case letters. Use the following output messages, exactly. Copy and paste for accuracy. Every output must end with a newline. You were assigned a seat. First class is now full. There are no seats left in First class. Business class is now full. There are no seats left in Business class. Economy class is now full. There are no seats left in Economy class. You made an invalid choice.

#include

int main( ) { char class = ' '; int f_seats = 0; //max 10 int b_seats = 0; //max 15 int e_seats = 0; //max 25 //fill some seats f_seats = 9; b_seats = 15; e_seats = 20; //display menu, get choice printf( "Choose your seat class " ); printf( "F - First class " ); printf( "B - Business class " ); printf( "E - Economy class " ); printf( "Your choice: " ); scanf( "%c", &class ); while(true)

{

printf("For the given seats, enter the option ... ");

printf("First Class -> F or f Business -> B or b Economy Class -> E or e Enter you choice ";

char choice;

scanf("%",%cchoice);

switch(choice)

{

case 'F' : if(First > 0)

{

First--;

printf("You were assigned a seat. ");

// if the seats are now empty

if(First == 0)

printf("First class is now full. ");

}

else

printf("There are no seats left in First class. ");

break;

case 'f' : if(First > 0)

{

First--;

printf("You were assigned a seat. ");

// if the seats are now empty

if(First == 0)

printf("First class is now full. ");

}

else

printf("There are no seats left in First class. ");

break;

case 'B' : if(Business > 0)

{

Business--;

printf("You were assigned a seat. ");

// if the seats are now empty

if(Business == 0)

printf"Business class is now full. ";

}

else

printf("There are no seats left in Business class. ");

break;

case 'b' : if(Business > 0)

{

Business--;

printf("You were assigned a seat. ");

// if the seats are now empty

if(Business == 0)

printf("Business class is now full. ");

}

else

printf("There are no seats left in Business class. ");

break;

// book economy class

case 'E' : if(Economy > 0)

{

Economy--;

printf("You were assigned a seat. ");

// if the seats are now empty

if(Economy == 0)

printf("Economy class is now full. ");

}

else

printf("There are no seats left in Economy class. ");

break;

case 'e' : if(Economy > 0)

{

Economy--;

printf("You were assigned a seat. ");

// if the seats are now empty

if(Economy == 0)

printf("Economy class is now full. ");

}

else

printf("There are no seats left in Economy class. ");

break;

default : printf("You made an invalid choice. ");

break;

}

printf(" To book another seat press y, else n ");

char ch;

scanf("%c",&char);

if(ch != 'y')

break;

} return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

Students also viewed these Databases questions

Question

LO3 Discuss the steps of a typical selection process.

Answered: 1 week ago