In c Create a flight booking program with several functional
In c++
Create a flight booking program with several functionalities (booking seat, clear a seat, check a seat, display all seats, etc...).
You will need to create an object of class Plane named “COSC1430”. Inside the plane, there will be two sections of seats – first class, and economy. Each should be created as double-dimensional arrays of type Seat. Then, with a loop, ask user to choose an option from a list of menu options (Book a Seat, Check a Seat, Display all Seats, Clear a Seat, Empty all Seats and Exit). Each menu option should be numbered (1 – 6), with Book a Seat being 1, and Exit being 6. The user should be able to select the corresponding menu option by entering just the number. When the user chooses to exit, clear all data of the seats and plane, and terminate the program.
In your program, you will need three files: main.cpp, Plane.h, Plane.cpp. Please note that we expect you to separate your declarations and implementations.
Plane.h/Plane.cpp
- A Struct Seat that contains the following:
o char status (‘-’ if the seat is empty, ‘x’ if the seat is booked)
o bool isBooked (true if seat is booked, false if available)
- A Class Plane that contains the following:
o Private:
Pointer variable Seat ** firstClass;
Pointer variable Seat ** economy;
int firstClassRows, firstClassCols, econRows, econCols;
o Public:
Default Constructor:
Ask for num of rows and cols of both firstClass and economy(using cin), and store them in the relevant member variables.
Initialize the double dimensional arrays for firstClass and economy
Overloaded Constructor with 4 parameters
Store all the row and col data into the member variables.
Initialize the double dimensional arrays for firstClass and economy
displaySeats function
Print (formatted neatly) all the seats in correct order (both firstClass and
economy)
The user should be able to tell from the display which seats are available
and which are booked
bookSeat function
ask whether a user wants a seat in firstClass or economy
ask for the row they want to sit in, and the seat number in that row
If seat is available, book it. Else, inform user that it’s already booked
checkSeat function
ask if user want firstClass or economy seat
ask for the row/col numbers of the seat they want to check
Inform user whether or not the seat is booked
clearSeat function
ask whether user wants to clear firstClass or economy seat
ask for the row/col numbers of the seat they want to clear
If booked, empty the seat. Else, inform user that seat was not booked
clearAllSeats function
• clean all seat on the plane and put it back to empty
Destructor
Delete all seats in the plane
MUST Delete two dimensional arrays
Will be called when the user exits the program
Getters/setters for private variables as needed
Main:
o Createanobjectnamed“COSC1430”oftypePlane
o Make a loop that allow the user to continue using the program until the user chooses to
exit
o Terminate the program.
Required materials:
1. Struct Seat
2. Class Plane
a. Default constructor
b. Overloaded constructor
c. displaySeats function
d. bookSeat function
e. showSeat function
f. clearSeat function
g. clearAllSeats
h. Getters/setters as necessary
i. Destructor
- Note: we did not specify what type of function or how many parameters need to be involve with in each function, if you have all function working as intended and the program compile.
- You may have extra functions that give extra functionality to the program, however these functions will not be considered for grading.
- You MUST delete your two-dimensional arrays to clear your allocated memory right before the program exits. Points will be deducted if you do not completely clean up memory allocation.
- Please note that there are NO global variables allowed.
Example Console Output:
You can customize the output as you like, just keep the format easy to read.
input: 4 hich section: 1 or 2 ROW: COL: COSC1430 PLANE SEATING MAP First Class Pick one of these options 1. Display all seat 2. Check a seat 3. Clear a seat 4. Book a seat 5. Empty all seat 6. Exit input 1 COSC1430 PLANE SEATING MAP Economy First Class Pick one of these options . Display all seat 2. Check a seat 3. Clear a seat 4. Book a seat 5. Empty all seat 6. Exit input: EconomySolution
Plane.h
#ifndef PLANE_H
#define PLANE_H
struct Seat
{
char status;
bool isBooked;
};
class Plane
{
private :
Seat **firstClass;
Seat **economy;
int firstClassRows;
int firstClassCols;
int econRows;
int econCols;
public :
Plane();
Plane(int, int , int ,int);
void displaySeats();
void bookSeat();
void checkSeat();
void clearSeat();
void clearAllseats();
~Plane();
};
#endif
Plane.Cpp
#include <iostream>
#include <iomanip>
#include \"Plane.h\"
using namespace std;
Plane::Plane()
{
int r11, c11, r21, c21;
cout<<\"\ Enter the rows and colums in first class: \";
cin>>r11>>c11;
cout<<\"\ Enter the rows and colums in economy class: \";
cin>>r21>>c21;
Plane(r11, c11, r21, c21);
}
Plane::Plane(int r1, int c1, int r2, int c2)
{
this->firstClassRows=r1;
this->firstClassCols=c1;
this->econRows=r2;
this->econCols=c2;
firstClass = new Seat *[r1];
for (int i = 0; i < r1; i++) {
firstClass[i] = new Seat[c1];
}
for (int i = 0; i < firstClassRows; i++) {
for (int j = 0; j < firstClassCols; j++) {
firstClass[i][j].status=\'-\';
firstClass[i][j].isBooked=false;
}
}
economy = new Seat *[r2];
for (int i = 0; i < r2; i++) {
economy[i] = new Seat[c2];
}
for (int i = 0; i < econRows; i++) {
for (int j = 0; j < econCols; j++) {
economy[i][j].status=\'-\';
economy[i][j].isBooked=false;
}
}
}
void Plane::displaySeats(){
cout<<\"Innn\"<<firstClassRows;
cout<<\"First class\"<<endl;
cout<<\"____________\"<<endl;
for (int i = 0; i < firstClassRows; i++) {
for (int j = 0; j < firstClassCols; j++) {
cout<<firstClass[i][j].status<<\" \";
}
cout<<endl;
}
cout<<\"Economy\"<<endl;
cout<<\"____________\"<<endl;
for (int i = 0; i < econRows; i++) {
for (int j = 0; j < econCols; j++) {
cout<<economy[i][j].status<<\" \";
}
cout<<endl;
}
}
void Plane:: bookSeat(){
cout<<\"Select class\ 1. First Class\ 2. Economy\ \";
int ch, r, c;
cin>>ch;
bool booked=false;
while(!booked)
{
cout<<\"Enter the row and column\ \";
cin>>r>>c;
switch(ch)
{
case 1:
if(firstClass[r-1][c-1].isBooked==false){
firstClass[r-1][c-1].isBooked=true;
firstClass[r-1][c-1].status=\'*\';
cout<<\"Booking sucessfull\ \";
booked=true;
break;
}
else
{
cout<<\"Entered seat unavilable, Enter another seat\ \";
booked=false;
break;
}
case 2:
if(economy[r-1][c-1].isBooked==false){
economy[r-1][c-1].isBooked=true;
economy[r-1][c-1].status=\'*\';
cout<<\"Booking sucessfull\ \";
booked=true;
break;
}
else
{
cout<<\"Entered seat unavilable, Enter another seat\ \";
booked=false;
break;
}
}
}
}
void Plane::checkSeat(){
cout<<\"Select class\ 1. First Class\ 2. Economy\ \";
int ch, r, c;
cin>>ch;
cout<<\"Enter the row and column\ \";
cin>>r>>c;
if(ch==1)
{
cout<<\"The seat is booked: \"<<firstClass[r-1][c-1].isBooked;
}
else if(ch==2)
{
cout<<\"The seat is booked: \"<<economy[r-1][c-1].isBooked;
}
else
{
cout<<\"Wrong choice\"<<endl;
}
}
void Plane::clearSeat()
{
cout<<\"Select class\ 1. First Class\ 2. Economy\ \";
int ch, r, c;
cin>>ch;
cout<<\"Enter the row and column\ \";
cin>>r>>c;
if(ch==1)
{
cout<<\"The seat is Cleared\ \";
firstClass[r-1][c-1].isBooked=false;
firstClass[r-1][c-1].status=\'-\';
}
else if(ch==2)
{
cout<<\"The seat is Cleared\ \";
economy[r-1][c-1].isBooked=false;
economy[r-1][c-1].status=\'-\';
}
else
{
cout<<\"Wrong choice\"<<endl;
}
}
void Plane::clearAllseats(){
for (int i = 0; i < firstClassRows; i++) {
for (int j = 0; j < firstClassCols; j++) {
firstClass[i][j].status=\'-\';
firstClass[i][j].isBooked=false;
}
}
for (int i = 0; i < econRows; i++) {
for (int j = 0; j < econCols; j++) {
economy[i][j].status=\'-\';
economy[i][j].isBooked=false;
}
}
}
Plane::~Plane(){
delete firstClass;
delete economy;
}
Main.cpp
#include <iostream>
#include \"plane.h\"
using namespace std;
int main(){
Plane plane(4,4,4,4);
plane.displaySeats();
while(1)
{
cout<<\"Pick one of these options\"<<endl;
cout<<\"1. Display all Seat.\"<<endl;
cout<<\"2. Check a Seat.\"<<endl;
cout<<\"3. Clear a Seat.\"<<endl;
cout<<\"4. Book a Seat.\"<<endl;
cout<<\"5. Empty all Seat.\"<<endl;
cout<<\"6. Exit.\"<<endl;
int ch;
cin>>ch;
switch(ch)
{
case 1:
plane.displaySeats();
break;
case 2:
plane.checkSeat();
break;
case 3:
plane.clearSeat();
break;
case 4:
plane.bookSeat();
break;
case 5:
plane.clearAllseats();
break;
case 6:
plane.~Plane();
exit(0);
break;
}
}
system(\"pause\");
return 0;
}