C program : You are now allowed to use the following in additional to the techni
ID: 3726841 • Letter: C
Question
C program : You are now allowed to use the following in additional to the techniques of the previous chapters: • arrays • multidimensional arrays • variable length arrays • static local arrays • #define symbolic constants • character arrays to manipulate strings • string termination character • algorithm: Bubble sort • algorithm: Binary search • algorithm: Linear search of array
Q1: (Airline Reservation System) (50 points) A small airline has just purchased a computer for its new automated reservations system. The president has asked you to program the new system. You’ll write a program to assign seats on each flight of the airline’s only plane (capacity: 10 seats). Your program should display the following menu of alternatives: Please type 1 for "first class" Please type 2 for "economy" Please type 3 to display seating chart. Please type 4 to end ?
If the person types 1, then your program should assign a seat in the first-class section (seats 1– 5). If the person types 2, then your program should assign a seat in the economy section (seats 6–10). Your program should then print a boarding pass indicating the person's seat number and whether it’s in the first class or economy section of the plane. Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding element of the array to 1 to indicate that the seat is no longer available. Your program should, of course, never assign a seat that has already been assigned. When the first class section is full, your program should ask the person if it’s acceptable to be placed in the economy section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message "Next flight leaves in 3 hours." Your program should make use of functions.
Explanation / Answer
c code
#include <stdio.h>
void displaychart(int arr[])
{
printf("first class");
printf(" ");
for(int i=0;i<5;i++)
{
printf("%d ",arr[i]);
}
printf("economy class");
printf(" ");
for(int i=5;i<10;i++)
{
printf("%d ",arr[i]);
}
}
int main() {
int arr[10]={0};
int f=0;//for count the assign seat of first class
int s=5;//for count the assign seat of economy class
while(1)
{
printf(" Please type 1 for" first class" ");
printf(" ");
printf(" Please type 2 for" economy" ");
printf(" ");
printf(" Please type 3 to display seating chart");
printf(" ");
printf(" Please type 4 to end");
printf(" ");
int a;
scanf("%d",&a);
if(a==1)//for first class
{
if(f<=5)//if seat is avaible
{
f++;
arr[f-1]=1;
printf("your seat no id %d",f);
printf(" and it is first class");
printf(" ");
}
else if(s<=10)//seat is not avaible in first calss but avaible in economy.
{
printf(" first class is full . if you want to take seat in economy then please press y for YES otherwise n for NO");
printf(" ");
char c;
scanf("%c",&c);
if(c=='y')//for yes;
{
s++;
arr[s-1]=1;
}
if(c=='n')//for NO
{
printf("Next flight leaves in 3 hours.");
printf(" ");
}
}
}
if(a==2)//for economy
{
if(s<=10)//if seat is avaible
{
s++;
arr[s-1]=1;
printf("your seat no id %d",s);
printf(" and it is economy class ");
printf(" ");
}
else if(f<=5)//seat is not avaible in economy calss but avaible in first class.
{
printf(" first class is full . if you want to take seat in economy then please press y for YES otherwise n for NO");
printf(" ");
char c;
scanf("%c",&c);
if(c=='y')//for yes
{
f++;
arr[f-1]=1;
}
if(c=='n')//for no
{
printf("Next flight leaves in 3 hours.");
printf(" ");
}
}
}
if(a==3)//for displaychart
{
displaychart(arr);
printf(" ");
}
if(a==4)//for exit
{
break;
}
}
return 0;
}
if you got my point then please like
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.