This program will allow the user to keep track of airline reservations. The prog
ID: 665299 • Letter: T
Question
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:
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.
12 34 Row 1 ## ## Row 2 ## ## Row 3 ## ## Row 4 ## ## Row 5 ## ## 123 456 Row 6 ### ### Row 7 ### ### Etc.Explanation / Answer
#include <iostream>
#include <cstdlib>
using namespace std;
void show_seatChart( const int* seat_array );
int reserve_seat( int* seat_array, int section );
int main()
{
// Variables declaration
const int SEATS = 20;
int seat_number[ SEATS ] = { 0 }, section, choice, seat;
do
{
// print the current seat chart.
show_seatChart( seat_number );
cout << " Please type 1 for First class." << " Please type 2 for Economy class." << " Input your choice: ";
// gets the seat section choice.
cin >> choice;
// if section is 1 seats starts from 1 else from 5.
section = ( choice == 1 ? 0 : 5 );
// reserve the seat.
seat = reserve_seat( seat_number, section );
// if seat not reserved.
if( !seat )
{
cout << ( choice == 1 ? "First Class" : "Economy Class" ) << " section has been filled! ";
system("pause");
}
}while( seat_number[4] == 0 || seat_number[19] == 0 );
system("cls");
cout << "Both sections have been filleed! ";
system("PAUSE");
return 0;
}
// prints the seat chart of each section.
void show_seatChart( const int* seat_array )
{
int i;
system( "cls" );
// message.
cout << " Welcome to airline reservation system " << " Seats in first class section: ";
// prints the seats that are not reserved. seat = 0.
for( i = 0; i < 20; i++ )
{
if( i == 5 ) cout << " Seats in economy class section: ";
if( seat_array[ i ] == 0 ) cout << "seat no." << i + 1 << endl;
}
}
int reserve_seat( int* seat_array, int section )
{
for( int seat = section; seat < 5 + section; seat++ )
// finds the un-reserved seat.
if( !( seat_array[ seat ] ) )
{
// reserve the seat.
seat_array[ seat ] = 1;
system( "cls" );
// issue the message that seat number is assigned.
cout << "You are assigned seat no." << seat + 1 << " in ";
cout << ( ( section == 0 ) ? " First class" : "Economy" ) << " section! ";
system("PAUSE");
return 1;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.