Problem 20
Question
( 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".
Step-by-Step Solution
VerifiedKey Concepts
Program Design
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
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
- 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
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.