Q1 in c-programming: xHomework-07-Spring-20 x C Chegg Study | Guided Sc x repl.i
ID: 3727326 • Letter: Q
Question
Q1 in c-programming:
xHomework-07-Spring-20 x C Chegg Study | Guided Sc x repl.it -Quiz problems x Dashboard C 1 file://home/chronos/u-098f0a422b1 94aa432f0e5b77b6868e769e8f3ab/Downloads/Homework-07-Spring-2018.pdf E ESPN: The worldwi comingSoon.net M IMDb Movies, TV a O YouTube. Movies Movie Trail a Amazon.com Onlin Wells Fargo-Perso R welcome to Faceb CapitalOne Credit gor algorithm: Binary search . algorithm: Linear search of array Work on format style!!! Points may be deducted for code that is not properly styled. 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 displa Please type 4 to end y seating chart. 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 planeExplanation / Answer
#include <stdio.h>
#include<stdlib.h>
int a[10]={0};
void bookticket(int choice, int visited){
int i,s,flag;
if(choice == 1){
flag=0;
for(i=0;i<5;i++){
if(a[i]==0){
printf("BOARDING PASS: ");
printf("Your Seat no is: %d ",i+1);
printf("Class : First Class ");
a[i]=1;
flag=1;
break;
}
}
if(flag==0){
printf("First class is full. is it acceptable to place in economy type 1 for yes or 2 for no ");
scanf("%d",&s);
if(s==1){
if(visited==0)
bookticket(2,1);
else{
printf("Flight Is Already Full. ");
printf("Next Flight Leaves In 3 Hours ");
exit(0);
}
}
else{
printf("Next Flight Leaves In 3 Hours ");
exit(0);
}
}
}
else{
flag=0;
for(i=5;i<10;i++){
if(a[i]==0){
printf("BOARDING PASS: ");
printf("Your Seat no is: %d ",i+1);
printf("Class : Economy ");
a[i]=1;
flag=1;
break;
}
}
if(flag==0){
printf("Economy is full. is it acceptable to place in Firstclass type 1 for yes or 2 for no ");
scanf("%d",&s);
if(s==1){
if(visited==0)
bookticket(1,1);
else{
printf("Flight Is Already Full. ");
printf("Next Flight Leaves In 3 Hours ");
exit(0);
}
}
else{
printf("Next Flight Leaves In 3 Hours ");
}
}
}
}
int main(void) {
int choice;
while(1){
printf("Enter Your choice ");
printf("Pleast type 1 for First Class ");
printf("Pleast type 2 for Economy ");
printf("Pleast type 3 to display seating arrangement ");
printf("Pleast type 4 to exit ");
printf(" ");
scanf("%d",&choice);
if(choice == 3){
printf("seating arrangement is: ");
int p=0;
while(p < 10){
if(a[p] == 0){
printf("%d ",p+1);
}
else{
printf("Booked ");
}
p++;
}
printf(" ");
}
if(choice ==1 || choice ==2){
bookticket(choice,0);
printf(" ");
}
if(choice == 4)
break;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.