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

Write a reservation system for an airplane flight. Assume the airline has 5 rows

ID: 3695064 • Letter: W

Question

Write a reservation system for an airplane flight. Assume the airline has 5 rows with 3 scats in each row (small plane!). Use a 2 dimensional array of type string to maintain a seating chart. In addition, create an array to be used as a waiting list in ease the plane is full. The waiting list should be "first come, first served"; that is, people who are added early to the list get priority over those added later. Also, you must maintain a second 2 dimensional array (a parallel array) that reflects the cost of the scats. Pricing for the scat is described below. Keep a running tally of the money earned on each flight. Allow the user the following options: Add a passenger to flight or waiting list Request the passenger list Display a chan of the scats in the airplane in tabular form, clearly titled, with the row and scat numbers clearly listed If scats arc available, let the passengers choose a scat. Inform the passenger of the seating cost. Add the passenger to the seating chan. If no scats arc available, place the passenger on the waiting list. Assume that the waiting list will grow to a maximum capacity of 10 passengers. Remove a passenger from a flight Search seating chart in the plane for a given name and delete this name from the seating chart. Ask for confirmation prior to deletion. There will not be any duplicate names. If waiting list is empty, update the array so scat is available. If waiting list is not empty, remove the first person from list, give him/her the newly vacated scat. Allow the user an option to display the passenger list or the seating price list as desired. Initialize the arrays that arc used in the following manner: Initialize string arrays to "xxxxx" Initalizc numeric arrays to 0.00 Scat pricing. Scats in the first 2 rows are first class and cost S200.00 Scats in the last 3 rows are coach class and cost $ 100.00 Scats in the middle receive a 10% "discomfort" discount. Create and implement functions as you think best. (Use them to the maximum extent.) Code your program so that the main() function is of small size and relies upon the functions created to achieve to functionality described above. [Remember, arrays arc always passed by reference. If you need to change an array, do it within a function and the array, as seen from the main, will also be changed.

Explanation / Answer

#include<stdio.h>
#include<stdbool.h>
#include<string.h>
char *p[5][3],*w[10];
int pr[5][3],amount=0,i,j,k=0;
//function to create and initialize all flight lists
void flightCharts()
{
//initilialize passengera nd waiting list to "xxxxx"
for(i=0;i<5;i++)
for(j=0;j<3;j++)
p[i][j]="xxxxx";
for(i=0;i<10;i++)
w[i]="xxxxx";
//initialize price array to 0
for(i=0;i<5;i++)
for(j=0;j<3;j++)
pr[i][j]=0;

}
//function to set prices to the seats
void setPrice()
{
int i,j;
for(i=0;i<2;i++)
for(j=0;j<3;j++)
pr[i][j]=200;
for(i=3;i<5;i++)
for(j=0;j<3;j++)
pr[i][j]=100;
for(j=0;j<3;j++)
pr[2][j]=90;

}
bool isPassavailable()
{
for(i=0;i<5;i++)
{
for(j=0;j<3;j++)
{
if(strcmp(p[i][j],"xxxxx")==0)
return true;
}
}
return false;
}
bool isWait()
{
for(i=0;i<10;i++)
{
if(strcmp(w[i],"xxxxx")==0)
return true;
}
return false;
}
void addPass()
{
char name[40];
int r,c;
printf("enter passenger name ");
scanf("%s",name);
//if seats available add passenger by asking seat detail
if(isPassavailable())
{
printf("choose a seat ");
printf(" enter row,column ");
scanf("%d",&r);
scanf("%d",&c);
*p[r][c]=*name;
amount=amount+pr[r][c];
}//if no seat available add to waiting list
else if(isWait()){
printf("passenger list is full you are being added to waiting list ");
while(strcmp(w[k],"xxxxx")!=0)
k++;
*w[k]=*name;
}//if waiting list full
else
{
printf("sorry, both passenger list and waiting list are full ");
}

}
void removePass()
{
char *x;
int r,c,flag=0;
printf("enter passenger name to remove ");
scanf("%s",x);
for(i=0;i<5;i++)
{
for(j=0;j<3;j++)
{
if(strcmp(x,p[i][j])==0)
{
flag=1;
r=i;
c=j;
*p[i][j]=*w[i];
for(k=0;k<10;k++)
*w[k]=*w[k+1];
}
}
}
if(flag==0)
printf("name not on list ");
}
void displayList()
{
for(i=0;i<5;i++)
{
for(j=0;j<3;j++)
{
printf("%s ",p[i][j]);
}
printf(" ");
}
}
void ViewPrice()
{
for(i=0;i<5;i++){
for(j=0;j<3;j++){
printf("%d ",pr[i][j]);
}
printf(" ");
}
}
int main()
{
int ch;
//take choice from user
printf("enter choice 1.Add Passenger 2.Remove Passenger 3.ViewList 4.ViewPrice ");
scanf("%d",&ch);
flightCharts();
setPrice();
switch(ch)
{
case 1:addPass();
break;
case 2:removePass();
break;
case 3: displayList();
break;
case 4: ViewPrice();
break;
default : printf("enter valid choice!! ");
break;
}
return 0;
}

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