(Airline Reservations System) A small airline has just purchased a computer for its new automated reservations system. You've been asked to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats). Your program should 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 (seats \(1-5\) ). If the person types 2 , your program should assign a seat in the economy section (seats \(6-10\) ). Your program should print a boarding pass indicating the person's seat number and whether it's in the first class or economy section of the plane. Use a one-dimensional array to represent the seating chart of the plane. Initialize all the elements of the array to false to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to true to indicate 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's 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."

Short Answer

Expert verified
Create an array to represent seats, display a menu for class selection, take user input, assign seats based on availability and class, handle full sections or offer alternatives, and give boarding passes. Repeat until all seats are assigned or flight is full.

Step by step solution

01

- Initialize the Seating Chart

Create a one-dimensional array with 10 elements to represent the seats on the plane. Initialize all elements to false, indicating that all seats are available.
02

- Display the Menu

Print the menu options to the console, prompting the user to choose either '1' for First Class or '2' for Economy.
03

- Get User Input

Take input from the user. If the input is not 1 or 2, prompt the user again until a valid input is received.
04

- Assign a Seat in First Class

If the user selects '1', loop through elements 0-4 of the array to check for an available seat (false). If found, set it to true and print the boarding pass.
05

- Assign a Seat in Economy

If the user selects '2', loop through elements 5-9 of the array to find an available seat (false). If found, set it to true and print the boarding pass.
06

- Handle Full Sections

If the chosen section is full, ask the user if they want to be placed in the alternative section. If yes, search for an available seat in that section. If no, print the message 'Next flight leaves in 3 hours.'
07

- Print Boarding Pass

Once a seat has been successfully assigned, print a boarding pass with the seat number and the class of the seat (First Class or Economy).
08

- Repeat the Process

Keep repeating steps 2-7 until all seats are filled. When all seats are taken, inform any additional users that the flight is full.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

Key Concepts

These are the key concepts you need to understand to accurately answer the question.

Array Manipulation in C++
When programming in C++, an array is a fundamental structure used to store a fixed-size sequential collection of elements of the same type. Array manipulation is an essential aspect in developing a reservations system since it allows us to efficiently handle multiple data items, such as a list of seats on an airplane.

For our airline reservations system, we use a one-dimensional array to represent the plane's seating chart. A one-dimensional array is like a list where each element can be accessed using an index. We initialize all 10 elements of the array to 'false' to signify that the seats are vacant. As seats are assigned, we update the respective index in the array to 'true', indicating that the seat is taken. Through array manipulation, we can easily assign seats, check for availability, and ensure that no double bookings occur.

To improve how the array is manipulated, we can also encapsulate the seat assignment logic into functions. This not only makes the code cleaner but also allows for better tracking of which seats have been filled and which ones remain open. It's also good practice to check for array boundaries to prevent accessing indices outside of the array, which can lead to runtime errors.
Conditional Statements in Programming
Conditional statements are a crucial part of programming, allowing the program to make decisions based on certain conditions. In the context of our airline reservations system, we rely on conditional statements to handle user input and seat assignments.

We prompt the user to choose between first class ('1') and economy ('2'). Based on the user's choice, a conditional statement determines where to search for an empty seat in the array that represents the seating chart. This is where 'if' and 'else if' statements are employed to check the user's input and to control the flow of the program depending on whether there are available seats in the selected class.

Furthermore, we use conditional statements to handle situations where a particular class is fully booked. The program asks if the user is willing to accept a seat in a different class. If they are ('yes'), we proceed to find them a seat; if not ('no'), a message is displayed accordingly. This logical decision-making process is fundamentally built upon the use of conditional statements.
Loop Constructs in C++
Loop constructs in C++ are essential for performing repetitive tasks without needing to write the same code over and over again. In our airline reservations system, we use loops to iterate through the array of seats to find an empty one.

For assigning seats, either in first class or economy, we use 'for' loops that iterate over a range of indices corresponding to the seats in the given class. For example, we loop over indices 0-4 for first class and 5-9 for economy class. Within the loop, we employ a conditional statement to check if the current seat is unoccupied, denoted by 'false'. When an available seat is found, we break out of the loop to reserve that seat, setting its value in the array to 'true'.

Loops are also handy for validating user input, ensuring they choose a valid option. We continue to prompt the user until they enter either '1' or '2'. The use of loops not only automates seat assignments but also guarantees a smooth and effective input process, ensuring a good user experience for the airline's customers.

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

(Write \(C++\) Statements) Write one or more statements that perform the following tasks for an array called fractions: a) Define a constant integer variable arraySize initialized to 10 b) Declare an array with arraySize elements of type double, and initialize the elements to 0 . c) Name the fourth element of the array. d) Refer to array element 4. c) Assign the value 1.667 to array element 9 f) Assign the value 3.333 to the seventh element of the array. g) Print array elements 6 and 9 with two digits of precision to the right of the decimal point, and show the output that is actually displayed on the screen. h) Print all the array elements using a for statement. Define the integer variable i as a control variable for the loop. Show the output.

(Bubble Sort Enbancements) The bubble sort described in Exercise 7.11 is inefficient for large arrays. Make the following simple modifications to improve the performance of the bubble sort: a) After the first pass, the largest number is guaranteed to be in the highest-numbered element of the array; after the second pass, the two highest numbers are "in place," and so on. Instead of making nine comparisons on every pass, modify the bubble sort to make eight comparisons on the second pass, seven on the third pass, and so on. b) The data in the array may already be in the proper order or near-proper order, so why make nine passes if fewer will suffice? Modify the sort to check at the end of each pass if any swaps have been made. If none have been made, then the data must already be in the proper order, so the program should terminate. If swaps have been made, then at least one more pass is needed.

(Double Array Initialization) Label the elements of a 3 -by- 5 two-dimensional array sales to indicate the order in which they're set to zero by the following program segment: for ( row = 0; row < 3; ++row ) for ( column = 0; column < 5; ++column ) sales[ row ][ column ] = 0;

(Fill in the Blanks) Fill in the blanks in each of the following: a) The names of the four elements of array p (int p[4];) are ___, ___ , ___ and ___. b) Naming an array, stating its type and specifying the number of elements in the array is called __ the array. c) By convention, the first subscript in a two-dimensional array identifies an element's ___ and the second subscript identifies an element's ___. d) An m-by-n array contains __ rows, __ columns and ___ elements. c) The name of the element in row 3 and column 5 of array \(d\) is __.

(Dotable Array Questions) Consider a \(2-\mathrm{by}-3\) integer array t. a) Write a declaration for t. b) How many rows does t have? c) How many columns does t have? d) How many elements does t have? e) Write the names of all the elements in row 1 of \(t\) f) Write the names of all the elements in column 2 of t. g) Write a statement that sets the element of t in the first row and second column to zero. h) Write a series of statements that initialize each element of t to zero. Do not use a loop. i) Write a nested for statement that initializes each element of to zero. j) Write a statement that inputs the values for the elements of trom the keyboard. k) Write a series of statements that determine and print the smallest value in array t. l) Write a statement that displays the elements in row 0 of t. \(\mathrm{m}\) ) Write a statement that totals the elements in column 3 of t. n) Write a series of statements that prints the array t in neat, tabular format. List the column subscripts as headings across the top and list the row subscripts at the left of each row.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free