227k views
4 votes
10.17 PROGRAM 2: Airline Seat Booking Program

C++ PLEASE!
This assignment must be completed on your own. Students may only ask for help from the TAs or instructors. If you have questions about the collaboration policy, please ask your instructor.
An airline uses a computer system to maintain flight sales information. For planning purposes, the airline must know what seats are on the plane, what seats are available, what seats are booked, and must have the ability to change the status of a seat from available to booked and vice versa. For this assignment, you will be implementing some of the functionality of the airline computer system. You will need to implement the following steps.
(1) Create the initial vectors for seats on the plane and seat status. You may assume that the plane has rows 1 through 5 and each row has seat A through E. The seat status is a 0 if the seat is available or a 1 if the seat is booked, and, therefore, not available.
(2) Implement a menu of options for the user. Following the initial setup of the vectors, the program outputs the menu. The program should also output the menu again after a user chooses an option. The program ends when the user chooses the option to Quit.
Ex:
Menu options:
1. Display All Seats Status:
2. Total Number of Available Seats:
3. Display Available Seats: 4. Book Seat:
5. Cancel Seat:
6. Change Seat:
7. Quit:
Please select an option: (3) Implement the "Display All Seats Status" menu option. Be sure to write a separate function for each menu option.
Ex:
Seat Status
1A 0
1B 0
1C 0
1D 0
1E 0
2A 0
...
(4) Implement the "Total Number of Available Seats" menu option.
Ex:
Number of available seats: 20
(5) Implement the "Display Available Seats" menu option. This function should show a list of available seats.
Ex:
Available seats:
1A
1B
1C
1D
1E
2A
...
(6) Implement the "Book Seat" menu option. This function should take in the seat to book and then should change the status of that seat to unavailable. After the function, the status of all seats should be displayed.
Ex:
Enter seat to book: 1A
Seat Status
1A 1
1B 0
1C 0
1D 0
1E 0
2A 0
...
(7) Add logic to the "Book Seat" menu option that will not allow the user to book a seat that is already booked.
Ex:
Enter seat to book: 1A
That seat is already taken.
Enter seat to book: 1B
Seat Status
1A 1
1B 1
1C 0
1D 0
1E 0
2A 0
...
(8) Implement the "Cancel Seat" menu option. This function should take in the seat to cancel and then should change the status of that seat to available. After the function, the status of all seats should be displayed.
Ex:
Enter seat to cancel: 1A
Seat Status
1A 0
1B 0
1C 0
1D 0
1E 0 2A 0
...
(9) Implement the "Change Seat" menu option. This function should take in the seat to cancel , the seat to book, and then should change the status of those seats. After the function, the status of all seats should be displayed.
Ex:
Enter seat to cancel: 1A
Enter seat to book: 1B
Seat Status
1A 0
1B 1
1C 0
1D 0
1E 0
2A 0
...

1 Answer

3 votes

This probabaly wont help since its in python(the only thing i know) but here

# Initialize seats and status

seats = []

status = []

for i in range(1, 6):

for j in ['A', 'B', 'C', 'D', 'E']:

seats.append(str(i) + j)

status.append(0)

# Function to display all seat status

def display_all_seats_status():

print("Seat Status")

for i in range(len(seats)):

print(seats[i], status[i])

# Function to display total number of available seats

def total_available_seats():

count = status.count(0)

print("Number of available seats:", count)

# Function to display available seats

def display_available_seats():

print("Available seats:")

for i in range(len(seats)):

if status[i] == 0:

print(seats[i])

# Function to book a seat

def book_seat():

seat = input("Enter seat to book: ")

index = seats.index(seat)

if status[index] == 0:

status[index] = 1

print("Seat", seat, "booked.")

else:

print("That seat is already taken.")

display_all_seats_status()

# Function to cancel a seat

def cancel_seat():

seat = input("Enter seat to cancel: ")

index = seats.index(seat)

status[index] = 0

print("Seat", seat, "cancelled.")

display_all_seats_status()

# Function to change a seat

def change_seat():

cancel_seat()

book_seat()

# Main program loop

while True:

print("Menu options:")

print("1. Display All Seats Status")

print("2. Total Number of Available Seats")

print("3. Display Available Seats")

print("4. Book Seat")

print("5. Cancel Seat")

print("6. Change Seat")

print("7. Quit")

option = input("Please select an option: ")

if option == '1':

display_all_seats_status()

elif option == '2':

total_available_seats()

elif option == '3':

display_available_seats()

elif option == '4':

book_seat()

elif option == '5':

cancel_seat()

elif option == '6':

change_seat()

elif option == '7':

quit()

User Felleg
by
8.9k points