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: 3827394 • 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

c++ code:

#include <iostream>
#include <string>
using namespace std;
void menu();
void countEmptySeats();
void listOfSeats();
void alphaList();
void assignPassenger();
void cancel();

struct Seat {
int seatNum;
bool seatStatus;
string firstName;
string lastName;
}seat[12];
int main()
{
char choice = 'a';
cout << "Welcome Podunk Airlines Reservation ";
for(int i=0;i<12;i++){
seat[i].seatNum = i+1;

}
while(choice != 'f'){
menu();
cin >> choice;
switch(choice){
case 'a' : countEmptySeats(); break;
case 'b' : listOfSeats(); break;
case 'c' : alphaList(); break;
case 'd' : assignPassenger(); break;
case 'e' : cancel(); break;
case 'f' : return 0; break;
default : menu();
}
}
cout << " ";
return 0;
}

void menu(){
cout << "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 Please choose : ";
}

void countEmptySeats(){
int count=0;
for(int i=0;i<12;i++){
if(seat[i].seatStatus == false){
count++;
}
}
cout << " Empty Seats Count : " << count <<" ";
}

void listOfSeats(){
for(int i=0;i<12;i++){
cout << seat[i].seatNum << " " << seat[i].firstName << " " << seat[i].lastName << " ";
}
}

void alphaList(){
Seat temp;
for(int i=0;i<12;i++){
for(int j=i+1;j<12-1;j++){
if(seat[j].firstName.compare(seat[j+1].firstName) < 0){
temp = seat[j];
seat[j] = seat[j+1];
seat[j+1] = temp;
}
}
}
}

void assignPassenger(){
int num;
while(true){
cout << "choose seat number[1-12] : ";
cin >> num;
if(seat[num-1].seatStatus == true){
cout << "seat already filled, choose other ";
}
else{
break;
}
}
cout << "Enter the firstname : ";
cin >> seat[num-1].firstName;
cout << " Enter the lastName : ";
cin >> seat[num-1].lastName;
seat[num-1].seatStatus =true;
}

void cancel(){
int num;
cout << "Enter the seat number : ";
cin >> num;
if(seat[num-1].seatStatus == false){
cout << "No reseravtion at this Seat ";
}
else{
seat[num-1].seatStatus =false;
seat[num-1].firstName = "";
seat[num-1].lastName = "";
cout << "reseravtion cancelled ";
}
}