C Program. relevant comments and intentions should be included. You are now allo
ID: 3724528 • Letter: C
Question
C Program. relevant comments and intentions should be included.
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 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 display seating chart. Please type 4 to endExplanation / Answer
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
//STRUCTURE
typedef struct{
char flightNo[5];
char date[12];
char time[6];
char gate[3];
}Flight;
Flight flight={"YZ22","10-12-2008","20:30","RT"};
typedef struct{
char name[30];
char booking_ID[3];
int seats;
}Seat;
Seat choice[4][5];
void displaymenu();
void booking();
void seat();
void ticket();
void records();
void looping();
void exit_();
//Variables
int selection;
int i;
int j;
int seats_num[20]={0};
int booking_ID=100;
int seatsAvailable=20;
int password;
int main(void)
{
displaymenu();
while(selection!=4)
{
looping();
}
return 0;
}
void displaymenu()
{
printf(" ");
printf(" Airline System "
" ======================= "
" MENU "
" ======================= "
" 1.BOOKING "
" 2.SEAT "
" 3.RECORDS "
" 4.EXIT ");
printf(" Enter your selection : ");
scanf("%d",&selection);
looping();
return;
}
//looping()
void looping()
{
switch(selection)
{
case 1:
booking();
break;
case 2:
seat();
break;
case 3:
records();
break;
case 4:
exit_();
break;
default:
printf(" Invalid selecion.Try again ");
}
return;
}
//booking
void booking()
{
for(i=0;i<4;i++)
for(j=0;j<5;j++)
{
printf(" Please enter seats number : ");
scanf("%d",&choice[i][j].seats);
fflush(stdin);
if(choice[i][j].seats<=seatsAvailable)
{
printf(" Please enter passenger name : ");
scanf("%[^ ]",choice[i][j].name);
fflush(stdin);
ticket();
booking_ID++;
}
seatsAvailable=seatsAvailable-choice[i][j].seats;
system("pause");
system("cls");
displaymenu();
}
if (seatsAvailable<0)
{
printf(" ");
printf(" SORRY, the flight is fully booked ");
printf(" =================END================= ");
displaymenu();
}
if(choice[i][j].seats>seatsAvailable)
{
printf(" ");
printf(" The flight leave %d seats ",seatsAvailable);
displaymenu();
}
return;
}
void ticket()
{
printf(" ");
printf(" -----------------AIRLINE BOOKING TICKET---------------- ");
printf(" ============================================================ ");
printf(" Booking ID : %d Flight No : %s ",booking_ID,flight.flightNo);
printf(" Passenger : %s ",choice[i][j].name);
printf(" Date : %s ",flight.date);
printf(" Time : %s ",flight.time);
printf(" Gate : %s ",flight.gate);
printf(" Seats No. : %d%c ",i+1,j+65);
printf(" ============================================================ ");
return;}
//seat
void seat()
{
printf(" A B C D E ");
for(j=0;j<5;j++)
{
printf("%d ",booking_ID);
}
for(i=0;i<4;i++)
{
printf(" ");
printf("%d ",i+1);
}
system("pause");
system("cls");
displaymenu();
return;
}
void records() //For Staff to View the flight's records
{
printf(" Please enter password: ");
scanf("%d", &password); //111
if (password==111)
{
system("cls");
printf(" ==================================== ");
printf(" ALL FLIGHT RECORDS ");
printf(" ==================================== ");
printf(" Seats Available left : %d ",seatsAvailable);
ticket();
system("pause");
system("cls");
displaymenu();
}
else
{
printf(" Invalid password ");
system("pause");
system("cls");
displaymenu();
}
return;
}
void exit_()
{
printf(" Thank you for using this system ");
exit(1);
return;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.