Question

C++ Create a class called Plane, to implement the functionality of the Airline Reservation System. Write...

C++

  • Create a class called Plane, to implement the functionality of the Airline Reservation System.
  • Write an application that uses the Plane class and test its functionality.
  • Write a method called CheckIn() as part of the Plane class to handle the check in process
    • Prompts the user to enter 1 to select First Class Seat (Choice: 1)
    • Prompts the user to enter 2 to select Economy Seat (Choice: 2)
    • Assume there are only 5-seats for each First Class and Economy
    • When all the seats are taken, display no more seats available for you selection
    • Otherwise it displays the seat that was selected.
    • Repeat until seats are filled in both sections
    • Selections can be made from each class at any time.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C++ program to implement the functionality of the Airline Reservation System.
#include <iostream>
using namespace std;

class Plane
{
private :
   bool seatEconomy[5]; // array of seats in economy class
   bool seatFirstClass[5]; // array of seats in first class
   // helper functions
   int economyEmptySeat();
   int firstClassEmptySeat();
public:
   Plane();
   void CheckIn();
};

// constructor to initialize all seats in empty status at the start
Plane::Plane()
{
   for(int i=0;i<5;i++)
   {
       seatEconomy[i] = false;
       seatFirstClass[i] = false;
   }
}

// function to return the index of first empty seat in economy class, else -1 if no empty seats
int Plane::economyEmptySeat()
{
   for(int i=0;i<5;i++)
       if(seatEconomy[i] == false)
           return i;
   return -1;
}

// function to return the index of first empty seat in first class, else -1 if no empty seats
int Plane:: firstClassEmptySeat()
{
   for(int i=0;i<5;i++)
       if(seatFirstClass[i] == false)
           return i;
   return -1;
}

// function to allow users to check in until all the seats are reserved
void Plane:: CheckIn()
{
   int choice, index;
   // loop that continues till all the seats are reserved in both economy and first class
   while((economyEmptySeat() != -1) || (firstClassEmptySeat() != -1))
   {
       // input the type of seat
       cout<<endl<<"Please type 1 for first class and press 2 for economy: ";
       cin>>choice;
       if(choice == 1) // first class
       {
           index = firstClassEmptySeat(); // get the index of the next seat free , -1 is first class is full
           // if full, display the message
           if(index == -1)
               cout<<"No more seats available for your selection. "<<endl;
           else
           {
               // allocate the seat and display this information
               seatFirstClass[index] = true;
               cout<<"You have been allocated seat : "<<(index+1)<<" in first class"<<endl;
           }
       }else if(choice == 2) // economy class
       {
           index = economyEmptySeat(); // get the index of the next seat free , -1 is economy is full

           // if full, display the message
           if(index == -1)
               cout<<"No more seats available for your selection. "<<endl;
           else
           {
               // allocate the seat and display this information
               seatEconomy[index] = true;
               cout<<"You have been allocated seat : "<<(index+1)<<" in economy class"<<endl;
           }
       }
       else // invalid choice
           cout<<"Invalid choice"<<endl;
   }

   cout<<"All seats are booked. Thank you for using the application"<<endl;
}

int main() {

   Plane plane; // create an object of Plane class
   plane.CheckIn(); // simulate the process of check in until all seats are booked in the flight
   return 0;
}
//end of program

Output:

Add a comment
Know the answer?
Add Answer to:
C++ Create a class called Plane, to implement the functionality of the Airline Reservation System. Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For this week's assignment , create and complete a Windows application for the following question. Airline...

    For this week's assignment , create and complete a Windows application for the following question. Airline Reservation System: An airline has just bought a computer for its new reservation system. Develop a new system to assign seats on the new airplane( capacity: 10 seats) Display the following alternatives: "Please type 1 for first class, and please type 2 for Economy". If the user enters 1, your application should assign a seat in the first class( seats 1-5). If the user...

  • Programming Language: C++ Develop a seat reservation system for your airline. Consider the following airline seating...

    Programming Language: C++ Develop a seat reservation system for your airline. Consider the following airline seating pattern: A         1          2          3          4          5          6          7          8          9          ……    100 B         1          2          3          4          5          6          7          8          9          ……    100 AISLE C         1          2          3          4          5          6          7          8          9          ……    100 D         1          2          3          4          5          6          7          8          9          ……    100 Either use 2D STL array (array that contains array) or 4 single dimensional STL arrays of size 100. Write a program to display a menu to the user with the options to reserve a seat of choice, reserve a window seat, reserve an aile seat, reserve a seat (any available), withdraw reservation, update reservation (change seat) and display...

  • C# WINDOWS FORMS APPLICATION (not CONSOLE APPLICATION ) (Please screenshot window form of this program and...

    C# WINDOWS FORMS APPLICATION (not CONSOLE APPLICATION ) (Please screenshot window form of this program and write code on computer. Thank you very much !) For this week's assignment , create and complete a Windows application for the following question. Airline Reservation System: An airline has just bought a computer for its new reservation system. Develop a new system to assign seats on the new airplane( capacity: 10 seats) Display the following alternatives: "Please type 1 for first class, and...

  • Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane {    //...

    Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane {    // checks customers in and assigns them a boarding pass    // To the human user, Seats 1 to 2 are for First Class passengers and Seats 3 to 5 are for Economy Class passengers    //    public void reserveSeats()    {       int counter = 0;       int section = 0;       int choice = 0;       String eatRest = ""; //to hold junk in input buffer       String inName = "";      ...

  • Programming language C++. (Airline Reservations System) A small airline has just purchased a computer for its...

    Programming language C++. (Airline Reservations System) A small airline has just purchased a computer for its new au- tomated reservations system. You have been asked to develop the new system. You’re to write an app to assign seats on each flight of the airline’s only plane (capacity: 10 seats). Display the following alternatives: Please type 1 for First Class and Please type 2 for Economy. If the user types 1, your app should assign a seat in the first-class section...

  • (Airline Reservations System) A small airline has just purchased a computer for its new automated reservations system

    (Airline Reservations System) 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 scats).Your program should display the following menu of alternatives:Please type 1 for "first class"please type 2 for "economy"If the person types 1 , then your program should assign a seat in the first class section (seats...

  • C++ Help please- kind of long. The aim is to implement a seat reservation system for...

    C++ Help please- kind of long. The aim is to implement a seat reservation system for a passenger airplane. We assume a small airplane with 10 rows and 4 seats per row. We assume that the seat chart is initially stored in a file “chartIn.txt” in the following format: 1   A B C D 2   A B C D 3   A B C D 4   A B C D 5   A B C D 6   A B C D 7  ...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

  • Program is in C++, program is called airplane reservation. It is suppose to display a screen...

    Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...

  • I could really use some help with this question! Thanks!! Must use C# and it must...

    I could really use some help with this question! Thanks!! Must use C# and it must be a console application ------------------------------------------------------------------------------------------------------------------------------ You start working on this w/o arrays just with seats: bool f1, f2,..., e1, e2,.... You can use Console application for now. A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You’re to write an app to assign seats on each flight of the airline’s...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT