Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

( 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 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 alternativesplease type 1 for "First Class" and Please type 2 for "Econony". 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 is 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 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 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 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".

Short Answer

Expert verified
Initialize seating array, handle user input, and iteratively assign the first available seat based on the class choice.

Step by step solution

01

Initialize Seating Array

Create an array `seats` of size 10, initialized to 0. This indicates all seats are empty: `seats = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]`.
02

Display Menu Options

Display the menu options for the user: 'Please type 1 for First Class and Please type 2 for Economy.' This allows the user to choose the section in which they wish to be seated.
03

Process User Input

Accept the choice from the user. If the user selects 1, try assigning a seat in the first class (indices 0-4). If the user selects 2, attempt to assign a seat in the economy class (indices 5-9).
04

Assign First Class Seat

Check seats 0 through 4 in the array for an empty seat. Assign the first available seat (value 0) by setting it to 1, and print a boarding pass with the seat number. If no seat is available, proceed to Step 5.
05

Handle Full First Class

If all first class seats are full, prompt the user with 'First Class is full. Would you like a seat in Economy? (y/n)'. Based on the response, either assign an economy seat or display 'Next flight leaves in 3 hours' if the response is 'n'.
06

Assign Economy Seat

For a request in economy, check seats 5 through 9 for availability. Assign the first open seat by setting its value to 1, and print a boarding pass with the seat number. If no seat is available, proceed to Step 7.
07

Handle Full Economy

If all economy seats are occupied, ask 'Economy is full. Would you like a seat in First Class? (y/n)'. If the user agrees ('y'), assign a first class seat if available. Otherwise, show the message 'Next flight leaves in 3 hours'.

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.

Program Design
Designing a program for an airline reservation system involves creating a structured plan that details how the reservation process will work. This exercise revolves around an airline with a single flight of 10 seats. By breaking down the program needs into sections, you ensure all scenarios are handled neatly.

The program must first initialize necessary data, such as a seating chart, and then present the options to the user. Introducing a simple menu with choices for seating class allows users to select their preference easily. The program should also include error handling, such as what happens when seats in a section are fully booked and how to communicate this to the users.

Flowcharts or pseudocode can be handy tools during this phase. Think of them as visual guides that show the steps your program needs to take. A user-friendly design keeps the booking process straightforward and minimizes confusion or errors during operation.
Array Manipulation
In the context of this airline reservation system, array manipulation is crucial for tracking which seats are available and which are taken. An array is a data structure that stores data in a list format. Here, we use an array to represent the seating chart of the airplane. Each index in the array corresponds to a specific seat.

You start by initializing an array called `seats` with 10 elements, all set to 0. The value 0 indicates an empty seat. As seats are booked, the corresponding index is set to 1, denoting that the seat is now occupied.

In programming, you must loop through the array to find available seats when a customer selects a seating class. It's vital to ensure you only offer seats that are marked as available (i.e., 0). By manipulating the array correctly, the system can offer accurate seating choices and maintain a real-time seating chart.
Flight Booking Logic
The flight booking logic serves as the backbone of the reservation system, ensuring that all bookings are processed accurately and efficiently. When users choose a class, the program must determine the first available seat within that class. This requires checks based on the assigned indices:
  • First Class: indices 0 to 4
  • Economy Class: indices 5 to 9

The program first attempts to find a seat in the user's selected class. If all such seats are filled, the program prompts the user to accept an alternative class, if available. This decision-making process needs careful logic to avoid double booking and to handle cases where neither class has available seats.

Another critical aspect is maintaining user satisfaction. If you cannot meet the user's request, the program should gracefully inform them of the next steps, like suggesting another flight. Handling such exceptions is part of ensuring a smooth booking experience.
Seating Allocation
Seating allocation in this system is managed by checking through each section to find the first available seat when a customer's request comes in. When a client indicates their preferred class, the program iterates over the specific array section to see if any spots marked "0" (unoccupied) exist.

If a seat is found, the booking system updates the array to mark this seat as taken by switching the index value from 0 to 1. It then prints a boarding pass for the customer with their assigned seat number and class. If the desired section is full, the system offers an alternative within the available seats of the other class, implementing a fallback mechanism to maximize seat occupation.

This system of allocation ensures that all seating decisions are made efficiently and fairly, preventing inefficiencies such as empty seats flying free on fully booked flights. Proper allocation optimizes aircraft usage and enhances customer satisfaction by providing as many seat options as possible.

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

Use a two-dimensional array to solve the following problem. A company has four salespeople \((1 \text { to } 4)\) who sell five different products \((1 \text { to } 5) .\) Once a day, each salesperson passes in a slip for each different type of product sold. Each slip contains the following: a. The salesperson number b. The product number c. The total dollar value of that product sold that day Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last month is available. Write a program that will read all this information for last month's sales and summarize the total sales by salesperson by product. All totals should be stored in the two-dimensional array sales. After processing all the information for last month, print the results in tabular format with each of the columns representing a particular salesperson and each of the rows representing a particular product. Cross total each row to get the total sales of each product for last month; cross total each column to get the total sales by salesperson for last month. Your tabular printout should include these cross totals to the right of the totaled rows and to the bottom of the totaled columns.

(Selection Sort) A selection sort searches an array looking for the smallest element. Then, the smallest element is swapped with the first element of the array. The process is repeated for the subarray beginning with the second element of the array. Each pass of the array results in one element being placed in its proper location. This sort performs comparably to the insertion sortfor an array of \(n\) elements, \(n 1\) passes must be made, and for each subarray, \(n 1\) comparisons must be made to find the smallest value. When the subarray being processed contains one element, the array is sorted. Write recursive function selectionsort to perform this algorithm.

When this process is complete, the array elements that are still set to one indicate that the subscript is a prime number. These subscripts can then be printed. Write a program that uses an array of 1000 elements to determine and print the prime numbers between 2 and \(999 .\) Ignore element 0 of the array. (Bucket Sort) A bucket sort begins with a one-dimensional array of positive integers to be sorted and a two-dimensional array of integers with rows subscripted from 0 to 9 and columns subscripted from 0 to \(n 1\), where \(n\) is the number of values in the array to be sorted. Each row of the twodimensional array is referred to as a bucket. Write a function bucketsort that takes an integer array and the array size as arguments and performs as follows: a. Place each value of the one-dimensional array into a row of the bucket array based on the value's ones digit. For example, 97 is placed in row 7,3 is placed in row 3 and 100 is placed in row \(0 .\) This is called a "distribution pass." b. Loop through the bucket array row by row, and copy the values back to the original array. This is called a "gathering pass." The new order of the preceding values in the one-dimensional array is 100,3 and \(97 .\) c. Repeat this process for each subsequent digit position (tens, hundreds, thousands, etc.). On the second pass, 100 is placed in row 0,3 is placed in row 0 (because 3 has no tens digit) and 97 is placed in row \(9 .\) After the gathering pass, the order of the values in the one-dimensional array is 100,3 and \(97 .\) On the third pass, 100 is placed in row 1,3 is placed in row zero and 97 is placed in row zero (after the 3 ). After the last gathering pass, the original array is now in sorted order. Note that the two-dimensional array of buckets is 10 times the size of the integer array being sorted. This sorting technique provides better performance than a insertion sort, but requires much more memory. The insertion sort requires space for only one additional element of data. This is an example of the spacetime trade-off: The bucket sort uses more memory than the insertion sort, but performs better. This version of the bucket sort requires copying all the data back to the original array on each pass. Another possibility is to create a second two-dimensional bucket array and repeatedly swap the data between the two bucket arrays.

State whether the following are true or false. If the answer is false, explain why. a. An array can store many different types of values. b. An array subscript should normally be of data type float. c. If there are fewer initializers in an initializer list than the number of elements in the array, the remaining elements are initialized to the last value in the initializer list. d. It is an error if an initializer list contains more initializers than there are elements in the array. e. An individual array element that is passed to a function and modified in that function will contain the modified value when the called function completes execution.

(Print an array) Write a recursive function printarray that takes an array, a starting subscript and an ending subscript as arguments and returns nothing. The function should stop processing and return when the starting subscript equals the ending subscript.

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