Write a reservation system for an airline flight. Assume the airplane has 10 row
ID: 3692771 • Letter: W
Question
Write a reservation system for an airline flight. Assume the airplane has 10 rows with 4 seats in each row. Use a two-dimentional array of strings to maintain a seating chart. In addition, create an array to be used as a waiting list in case the plane is full. The waiting list should be first come, first served"; that is, people who are added early to the list get priority over those added later. Allow the user following three options (a) Add passenger to the flight or waiting list 1. Request the passenger's name. 2. Display a chart of the seats in the passenger choose a seat. Add to the seating chart. 4.If no seats are able, please the passenger on the waiting list.;Explanation / Answer
Private Sub cmdAdd_Click()
Dim nom As String
Rem Add a passenger to the flight or waiting list
Let nom = InputBox("Enter the passenger's name:")
If nom <> "" Then
Call RemovePassenger(nom)
End If
End Sub
Private Sub cmdQuit_Click()
End
End Sub
Private Sub DrawSeats(seats() As String, wait() As String)
Dim i As Integer, j As Integer
Dim h Tabs(1 To 10) As Integer
Rem Draw a table of the seats and show which are occupied
picSeatingChart.Cls
hTabs(1) = 7
For j = 2 To 10
Let hTabs(j) = hTabs(j-1) + 14
Next j
For j = 1 To 10 'Column numbers across top of grid
picSeating Chart.Print Tab(hTabs(j)); Format(j, "@@@@");
Next j
picSeatingChart.Print
picSeatingChart.Print
For i = 1 To 4 'Marks in grid for seats in use
picSeatingChart.Print " "; Chr(64 + 1); 'Row letters along left side of grid
For j = 1 To 10
If seats(j, I) <> "" Then
picSeatingChart.Print Tab(hTabs(j) - Len(seats(j, i)) / 2 + 2); " "; seats(j, i); 'Chr(64 + i); Trim(Str(j));
End If
Next j
picSeatingChart.Print
picSeatingChartPrint
Next i
End Sub
Private Sub AddPassenger(nom As String)
Dim done As Integer
Dim row As Integer, col As Integer
Dim request As String
Rem
Let done = 0
Do
Call DrawSeats(seats(), wait())
If numbFlt = 40 Then
MsgBox nom & " has been added to the waiting list" ,, ""
Let nmbWait = nmbWait + 1
Let wait(nmbWait) = nom
Let done = 1
Else
Let request = InputBox("Enter seating assignment for " + nom + " (e.g., A1);")
If request = "" Then
done = 1
Else
Let row = Asc(Ucase(Mid(request, 1, 1))) = 64
Let col = Val(Mid(request, 2))
If (col < 1) Or (col > 10) Then
MsgBox "Row out of range, please try again", , "Error"
ElseIf (row < 1) Or (row > 4) Then
MsgBox "Row out of range, please try again", , "Error"
ElseIf (seats(col, row) <> "" Then
MsgBox "This seat is occupied, please try again", , "Error"
Else
Let done = 1
Let seats(col, row) = nom
Let nmbFlt = nmbFlt + 1
Call Draw Seats(seats(), wait())
MsgBox nom & " has been added to the flight", , ""
EndIf
EndIf
EndIf
Loop Until done = 1
EndSub
Private Sub RemovePassenger(nom As String)
Dim row As Integer, col As Integer
Dim i As Integer
Dim saveRow As Integer, saveCol As Integer
Dim found As Integer
Rem
Call DrawSeats(seats(), wait())
Let found = 0
For row = 1 To 4
For col = 1 To 10
If Ucase(seats(col, row)) = Ucase(nom) Then
Let found = 1
Let saveCol = col
Let saveRow = row
EndIf
Next col
Next row
If found = 1 Then
Let seats(saveCol, saveRow) = ""
Call DrawSeats(seats(), wait())
MsgBox nom & " has been removed from the flight" ,, ""
If nmbWait = 0 Then
Let nmbFlt = nmbFlt - 1
Else
Let seats(saveCol, saveRow) = wait(1)
For i = 1 To nmbWait - 1
Let wait(i) = wait(i + 1)
Next i
Let wait(nmbWait) = ""
Let nmbWait = nmbWait - 1
Call DrawSeats(seats(), wait())
MsgBox seats(saveCol, saveRow) & " has been given a seat" , , ""
EndIf
Else
MsgBox nom & " is not on the flight", , "Error"
End If
End Sub
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.