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

Structures Write the Program in C++ only. Task : Create a seating reservation pr

ID: 3825499 • Letter: S

Question

Structures

Write the Program in C++ only.

Task: Create a seating reservation program for Podunk Airlines. The air fleet consists of a single plane with a seating capacity of 12. The plane makes one flight daily. Your program will maintain the reservation information for a single day.

Processing: Use a 12-element array of structures to store information about the 12-seat plane. The structures will include this information:

seat identification number (an integer from 1 to 12)

a Boolean variable that indicates whether or not the seat is currently assigned

the first name of the seat holder

the last name of the seat holder

The program should be user-friendly, providing a menu of these functions:

a). show the count of empty seats

b). show a list of all seats in numeric order, including assigned passenger names

c). show an alphabetical list of passengers and their seat numbers; don’t include empty seats

d). assign a passenger to a seat

e). cancel a seat reservation

f). quit

After the completion of a menu task other than f, the program should clear the screen and redisplay the menu for the user. When searching for a name or when sorting names, note that passengers may have the same last name; however, we will assume for our program that two passengers don’t have identical first and last names.

Input: Choice d in the menu will require the user to input the name of a passenger and a desired seat number. Choice e should permit the user to provide a passenger’s name or a seat number.

Output: All output may be directed to the screen.

Explanation / Answer

#include<iostream.h>
#include<string.h>
#include<conio.h>

#define SIZE 10

int count;
struct pass
{
   int id;
   int status;
   char fname[100];
   char lname[100];
};
typedef struct pass   passenger;


void bookSeat(passenger k[])
{
   //clrscr();
   if ( count == SIZE)
   {
       cout<<" Sorry booking is full. ";
       return;
   }

   for(int i=0; i < SIZE ;i++)
   {
       if( k[i].status == 1 )
       {
           cout << "Enter First Name and Last Name ";
           cin >> k[i].fname >>k[i].lname;
           k[i].id=i;
           k[i].status=2;
           count++;
           cout <<"Booking Done ";
           cout<<"Passenger ID is : " <<i<<". ";
           cout<<"Total passengers booked = "<< count<<" Free seats available = "
               << SIZE-count<<" ";
           break;
       }
   }
}


void listSeats(passenger p[])
{
   //clrscr();
   cout<<" passenger list: ";
   for(int i=0; i< SIZE ;i++)
   {
       if(p[i].status==2)
       {
           cout <<i<<"): "<<p[i].fname<<" "<<p[i].lname<<": ID="<<p[i].id<<endl;
       }
   }
}
void cancelBooking(passenger p[])
{
   int id;
   //clrscr();
   cout <<"Enter id to cancel ";
   cin >>id;
   if (id<0 || id >SIZE)
       {
           cout<<"ID doesnt exist ";
           return;
       }
   for(int i=0; i< SIZE ;i++)
   {
       if(p[i].id==id)
       {
           p[i].status=1;
           count--;
           cout <<" Cancelled ";
           break;
       }
   }
}

void emptySeats()
{
   //clrscr();
   cout << " Total "<<SIZE-count<<" seats available ";
}

int main()
{
   passenger p[SIZE];
   char op;
   //clrscr();
   for(int i = 0; i< SIZE; i++)
   {
       p[i].status = 1; // 1=free, 2=booked
   }

   count = 0;
   while(1)
   {
       cout << " 1 Book seat 2 Cancel booking 3 List Seats 4 Empty Seats 5 Exit: ";
       op = getche();

       switch(op)
       {
           case '1':
               bookSeat(p);
               break;
           case '2':
               cancelBooking(p);
               break;
           case '3':
               listSeats(p);
               break;
           case '4':
               emptySeats();
               break;
           case '5':
               return 0;
           default:
               cout<<" Wrong character pressed, try again. ";
       }
   }
}