/*This program will allow the user to keep track of airline reservations. The pr
ID: 672491 • Letter: #
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 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. ($300)
The first 5 rows($200) of coach will be more expensive than the last 5 rows($100).
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.
*/
Explanation / Answer
#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
#include <cstdlib>
using namespace std;
//function declarations
void menu();
void checkSeat();
void printTicket();
void displaySeating();
//global variables
const int economy = 100;
const int x = 9;
const int y = 5;
const int size = 50;
char seat[x][y];
double price, discount;
string type, sname, name[x][y];
bool answer;
int i,j;
void init()
{
char letters[11] = "ABCDEFGHIJ";
char letter;
for ( int i = 0; i < x; i++ )
{
//assign the letter of the i;
letter = letters[i];
int y = 0;
if(y < 5)
y ++;
seat[letter][j] = '0';
}
}
void menu()
{
{
cout << "Welcome ";
cout << "Please choose one of the following: ";
cout << "1. First Class ";
cout << "2. Economy ";
cout << "3. Seating allocation ";
cout << "4. Ticket holder ";
}
void checkSeat()
{
char cout << "Enter name:";
cin >> sname;
cout << "Do you want a specific seat:(yes/no) : ";
cin >> reply;
if( reply == 'yes' )
{
init();
cout << "Enter seat: ";
cin >> seat[x][y];
if(seat[x][y] == 'X')
{
seat[x][y] = 'X';
name[x][y] = sname;
}
else
{
int x = rand()%x;
int y = rand()%y;
while(seat[x][y] == 'X');
{
int x = rand()%x;
int y = rand()%y;
}
seat[x][y] = 'X';
name[x][y] = sname;
}
}
else
{
init();
int x = rand()%x;
int y = rand()%y;
while ( seat[x][y] = 'X')
{
int x = rand()%x;
int y = rand()%y;
}
seat[x][y] = 'X';
name[x][y] = sname;
}
void printTicket()
{
cout <<"Name: " << name << endl;
cout << "Seat No: " << seat << endl;
cout << "Ticket type: " << type << endl;
cout << "price: " << price << endl;
}
void displaySeating()
{
}
int main()
{
int choice;
srand(time(NULL));
//need this for random numbers for ( int count = 0 ;
count < 50 ;
count++)
{
menu();
cin >> choice;
switch (choice)
{
case 1: type = "First class";
init();
int x = 9;
{
checkSeat();
bool isleSeat1 = seat[x][1];
bool isleSeat2 = seat[x][2];
if ( isleSeat1 == true || isleSeat2 == true )
{
discount = 10 / 100 * firstClassPrice;
price = firstClassPrice - discount;
}
else
{
price = firstClassPrice;
}
}
break;
case 2: type = "Economy";
init();
while( x > 2 )
{
checkSeat();
bool isleSeat1 = seat[x][1];
bool isleSeat2 = seat[x][2];
if ( isleSeat1 == true || isleSeat2 == true )
{
discount = 10 / 100 * firstClassPrice;
price = firstClassPrice - discount;
}
else
{
price = firstClassPrice;
}
}
break;
case 3: printTicket();
break;
case 4: default: cout << "Incorrect ";
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.