Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
(Airline Reservations System) A small airline has just purchased a computer for its new automated reservations system. You have been asked to program the new new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats).
I have to write a program that display the following menu of alternatives-Please type 1 for "First Class" and Please type 2 for "Economy". If the person types 1, your program should assign a seat in the first class section (seat 1-5). If the person types 2, your program should assign a seat in the economy section (seat 6-10). Your program should print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane.
Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to inicate that the seat is no longer available.
Your program should, of course, never assign a seat that has already been assigned, When the first class section is full, your program should ask the person if it is acceptable to be placed in the economy section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message "Next flight leaves in 3 hours."
In in the process of declaring and initializing variables and arrays. This is what I have to so far. Tell me if I'm on the right track.
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <iomanip>using std::setw:
int main()
{const int seats[10] = { 0 };
int options;
int firstClass = 1;
int economy = 2;
int passenger = 0while ( passenger < 10 ) {
cout << " Please type 1 for "First Class" or type 2 for "Ecnonomy" ";
cin >> options;if ( options == 1 >

Sort of. Don't declare seats as const since you will need to change it's data as seats are filled. I'd use a char for options since the program will go loopy if someone enters a letter for "options" with the way it is now.
Your menu is ok... I guess you meant cout << "Please type 1 for \"First Class\" or type 2 for \"Second Class\""; ?
I'd test specific elements of seats directly for seeing if it's filled or not. Just keep a basic index for first class, and add an offset to index for second class.
HTH

I updated my code below. Sofar I a) declared and initialzed my variables and array b) began my loop. So now I am requesting ticket preference and starting the If statement. If the user types 1 then assign to first class and if they type 2 then assign economy seat. I know I need some statements within those if statements to set the conditions and also a to set the elements of the array to 1 to indicate that a seat is no longer available. Please help! I been spending days trying to figure this part out.
#include <iostream>
#include <iomanip>
using std::cout;
using std::endl;
using std::cin;
int main()
{
int seats[10] = { 0 };
int firstClass = 1;
int economy = 6;
int passenger = 0;
int selection;char answer;
for (int i = 1; i < 10; i++)
{
cout << endl;
cout << "Please type 1 for \"First Class\"" << endl;
cout << "Please type 2 for \"Economy\"" << endl;
cin >> selection;
if ( selection == 1 ) {
if (firstClass <= 5 {
cout << "Your first class seat is: " << firstClass << endl;
first++;
}else if (firstClass >= 5) {
cout << "The first class section is full."
<< "Would you like to sit in the economy
<< "section (Y or N)?";
cin >> answer;if (selection == 2)
{
cout << "Your economy seat is: " << economy << endl;
economy++
}
I drew out the job specifications, as how I want to do this program, but I am not sure how to get there. Here it is below:Declare & initialize variables
Initialize arrayBegin loop
Request ticket preference
Case First Class
If seat FC available
Assign First Class Seat
Else
If would like economy
If Economy Seat available
Assign Economy Seat
Else
Suggest next flight
End if
Else
Break
End if
End if
Case Economy
If seat available
Assign Economy Seat
Else
If would like First Class
If First Class Seat available
Assign First Class Seat
Else
Suggest next flight
End if
Else
Break
End if
End if
End Case
End Program

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |