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

Using c++, This program will allow the user to keep track of airline reservation

ID: 665673 • Letter: U

Question

Using c++, This program will allow the user to keep track of airline reservations. The program should display the seating chart for the airplane. It will use an * to indicate a seat is taken and the # to indicate the seat is available. The program will also display a menu which provides the user with several options. There will be two types of seats in the airplane: first class and coach, each of which will have a different cost. The program must make use of files, arrays and functions.
The airplane will have 5 rows in the first class section with 4 seats in each row, 2 on each side of the aisle and 10 rows in the coach section with 3 seats on each side of the aisle. The prices for all the first class seats will be the same. The first 5 rows of coach will be more expensive than the last 5 rows. The prices for the seats will be stored in a file called SeatPrices.txt . The program should read these values from the file and store the values in an array of doubles. This is an example of the seating chart:
             12 34
Row 1 ## ##
Row 2 ## ##
Row 3 ## ##
Row 4 ## ##
Row 5 ## ##
             123 456
Row 6 ### ###
Row 7 ### ###
Etc.
The menu will provide choices to reserve a seat(s) and display the total number of seats sold (indicating first class and coach), the total number of seats empty in a row, the total number of seats empty in the plane (indicating first class and coach), and the total amount of sales (in dollars).
Validation: The seat requested by the user is a valid row and seat number. The program should also make sure the seat is not already taken.
Seat prices
324.23
200.00
150.23

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;

int* cost;
int** first_class;
int** coach_section;
void read_data(){
   ifstream infile;
   infile.open("try.cpp");
   string s;
   while (infile.eof() != false){
       getline(infile,s);
       cost[i] = atof(s.c_str());
   }
}

bool first_class_full(){
   for (int i = 0; i < 5; i++){
       for (int j = 0; j < 4; j++){
           if (first_class[i][j] == 0) return true;
       }
   }
   return false;
}

bool eco_class_full(){
   for (int i = 0; i < 10; i++){
       for (int j = 0; j < 6; j++){
           if (coach_section[i][j] == 0) return true;
       }
   }
   return false;
}

void ticket_book(){
   cout << "WELCOME TO TICKET BOOKING" << endl;
   while (true){
       int seats;
       cout << "ENTER HOW MANY SEATS YOU WANT TO BOOK : ";
       cin >> seats;
       float amt = 0.0;
       while (seats > 3){
           int n;
           cout << "PRESS 1 FOR FIRST CLASS : ";
           cout << "PRESS 2 FOR SECOND CLASS : ";
           cout << "PRESS 0 FOR EXIT : ";  
           cin > n;
           if (n == 1){
               if (first_class_full() == true){
                   cout << "first class seats are not available " << endl;
                   continue;
               }
               while (true){
                   int row,col;
                   cout << "SELECT ROW FROM (1 to 5) : ";
                   cin >> row;
                   cout << "SELECT COLUMN FROM (1 to 4) : ";
                   cin >> col;
                   if (first_class[row-1][col-1] == 0){
                       first_class[row-1][col-1] = 1;
                       amt += cost[0];
                       break;
                   }
                   else{
                       cout << "THis is seat is full; try different seat " << endl;
                   }
               }
           }
           else if (n == 2){
               if (eco_class_full() == true){
                   cout << "first class seats are not available " << endl;
                   continue;
               }
               while (true){
                   int row,col;
                   cout << "SELECT ROW FROM (1 to 10) : ";
                   cin >> row;
                   cout << "SELECT COLUMN FROM (1 to 6) : ";
                   cin >> col;
                   if (coach_section[row-1][col-1] == 0){
                       coach_section[row-1][col-1] = 1;
                       if (row > 5)
                           amt += cost[2];
                       else
                           amt += cost[1];
                       break;
                   }
                   else{
                       cout << "THis is seat is full; try different seat " << endl;
                   }
               }
           }
           else{
               break;
           }
           seats--;
       }
       cout << "TOTAL AMOUNT NEED TO PAY IS " << amt << endl;
       char ch;
       cout << "PRESS Y for another booking " << endl;
       cin >> ch;
       if (ch == 'Y' || ch == 'y')   continue;
       break;
   }
}

int main(){
   cost = new int[3];
   first_class = new int*[5];
   for (int i = 0; i < 5; i++){
       first_class[i] = new int[4];
       for (int j = 0; j < 4; j++){
           first_class[i][j] = 0;
       }
   }

   coach_section = new int*[10];
   for (int i = 0; i < 10; i++){
       coach_section[i] = new int[6];
       for (int j = 0; j < 6; j++){
           coach_section[i][j] = 0;
       }
   }
  
   read_data();
   ticket_book();
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote