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: 3827301 • 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 <stdio.h>
#include <conio.h>
#include <iomanip.h>
#include <string.h>
#define BOOL int
#define TRUE 1
#define FALSE 0

struct Person
{
int SID;
BOOL Assigned; //a Boolean variable that indicates whether or not the seat is currently assigned
char FName[50]; //the first name of the seat holder
char LName[50]; //last name of the seat holder
};
const int TotalSeat=12;
Person p1[TotalSeat];

void printMenu()
{
cout<<" a). show the count of empty seats";
cout<<" b). show a list of all seats in numeric order, including assigned passenger names";
cout<<" c). show an alphabetical list of passengers and their seat numbers";
cout<<" d). assign a passenger to a seat";
cout<<" e). cancel a seat reservation";
cout<<" f). quit";
}

int funEmptySeat()
{
int i,EmptySeat=0;
for (i=0;i<TotalSeat;i++)
{
   if(p1[i].Assigned==0)
   {
   EmptySeat=EmptySeat+1;
   }
}
return EmptySeat;
}

void setAssigned()
{
int i;
for (i=0;i<TotalSeat;i++)
{
   p1[i].SID=i+1;
   p1[i].Assigned=0;
}
}

int main()
{
int CntEmptySeat;
char ch,response;
int i,EmptySeat;
int samedtl;
int seatNo;
char seatflag,FName[50],LName[50],FullName[100];
clrscr();
setAssigned();
do
{
   printMenu();
   cout<<" Enter your choice(character from a to f) : ";
   cin>>ch;
   switch(ch)
   {
   case 'a':
       CntEmptySeat=funEmptySeat();
       cout<<" Empty Seats : "<<CntEmptySeat;
       break;
   case 'b':

       CntEmptySeat=funEmptySeat();
       if (CntEmptySeat!=12)
       {
       cout<<" ";
       cout.width(10); cout<<"Seat Number";
       cout.width(20); cout<<"First Name";
       cout.width(20); cout<<"Last Name";
       cout<<" ------------------------";
       cout<<"---------------------------";
       for (i=0;i<TotalSeat;i++)
       {
           if(p1[i].Assigned==1)
           {
           cout<<" ";
           cout.width(10); cout<<p1[i].SID;
           cout.width(20); cout<<p1[i].FName;
           cout.width(20); cout<<p1[i].LName;
           }
       }
       }
       else
       {
       cout<<" All seats are empty!!!";
       }
       break;
   case 'c':
       cout<<"Not Implemented!!!";
       break;
   case 'd':
       seatflag='y';
       samedtl=0;
       do
       {
       cout<<" Enter desired seat Number(1 to 12) : ";
       cin>>seatNo;
       if(seatNo>12)
       {
           cout<<" Seat number not availble(Must provide between 1 to 12)";
           cout<<" Do you want to allocate another seat(y/n)? : ";
           cin>>seatflag;

       }

       else if (p1[seatNo-1].Assigned==0)
       {

           do
           {
           samedtl=0;
           p1[seatNo-1].SID=seatNo;
           cout <<" Enter First Name: ";
           cin>>FName;
           cout <<" Enter Last Name : ";
           cin>>LName;
           CntEmptySeat=funEmptySeat();
           if (CntEmptySeat!=12)
           {


           for(i=0;i<TotalSeat;i++)
           {
               if (strcmp(p1[i].FName,FName)==0 && strcmp(p1[i].LName,LName)==0)
               {
               cout<<"Same name alreay available...provide different name";
               samedtl=1;
               break;
               }
           }
           }

           }while(samedtl==1);
           strcpy(p1[seatNo-1].FName,FName);
           strcpy(p1[seatNo-1].LName,LName);
           p1[seatNo-1].Assigned=TRUE;
           cout<<" Seat booked!!!";
           seatflag='n';

       }
       else if(p1[seatNo-1].Assigned==1)
       {
           cout<<" Seat is already occupied!!!";
           cout<<" Do you want to allocate another seat(y/n)? ";
           cin>>seatflag;
       }
       }while(seatflag=='y');
       break;
   case 'e':
       int cancelpref,find=0;
       char UserName[100];

       cout<<"Cancel resesrvation by";
       cout<<" 1.Seat Number"<<" 2.Name(Fname and LName -->septated by space)";
       cout<<" Enter your choice(1/2) : ";
       cin>>cancelpref;
       if(cancelpref==1)
       {
       cout<<" Enter seat number : ";
       cin>>seatNo;
       if (seatNo>12)
       {
           cout<<" Seat number not availble(Must provide between 1 to 12)";
       }
       else if(p1[seatNo-1].Assigned==1)
       {
           p1[seatNo-1].Assigned=0;
           strcpy(p1[seatNo-1].FName,"");
           strcpy(p1[seatNo-1].LName,"");
           find=1;
       }
       else
       {
           cout<<" Seat is still vacant...";
       }
       }
       else if(cancelpref==2)
       {
       cout<<" Enter First Name :";
       cin>>FName;
       cout<<" Enter Last Name : ";
       cin>>LName;
       strcat(UserName,FName);
       strcat(UserName," ");
       strcat(UserName,LName);
       for (i=0;i<TotalSeat;i++)
       {
           if (p1[i].Assigned==1)
           {
           strcat(FullName,"");
           strcat(FullName,p1[i].FName);
           strcat(FullName," ");
           strcat(FullName,p1[i].LName);
           cout<<" StructNm : "<<FullName<<" User : "<<UserName;
           if(strcmp(FullName,UserName)==0)
           {
               find=1;
               p1[seatNo-1].Assigned=0;
               strcpy(p1[seatNo-1].FName,"");
               strcpy(p1[seatNo-1].LName,"");
               break;
           }
           }

       }
       if (find==0)
       {
           cout<<" Provided name not available in list";
       }
       else
       {
           cout<<" Reservation cancelled...";
       }
       }
       break;
   case 'f':
       return 0;
   default:
       cout<<" Entered option not available...";
       break;

   }
   cout<<" Press any key to continue...";
   getch();
   if(ch!='f')
   {
   clrscr();
   }
}while(ch!='f');
return 0;
}