7. Airline Reservations. Write a reservation system for an airline flight. Assum
ID: 3688918 • Letter: 7
Question
7. Airline Reservations. Write a reservation system for an airline flight. Assume the airplane has 12 rows with 4 seats in each row. Use a two-dimensional array of strings to maintain a seating chart In addition, create anárray 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 so the list get priority over those addéd later. Allow the user the following three options: (a) Add a passenger to the flight or waiting list. 1. Request the passenger's name 2. Display a chart of the seats in the airplane in tabular form. 3. If seats are available, let the passenger choose a seat. Add the passenger to the seat- ing chart. 4. If no seats are available, place the passenger on the waiting list. (b) Remove a passenger from the flight. 1. Request the passenger's name. 2. Search the seating chart for the passenger's name and delete it. 3. If the waiting list is empty, update the array so the seat is available. 4. If the waiting list is not empty, remove the first person from the list, and give him cor 2 Sench the senting chart for the pasenger' name and delete it. her the newly vacated seatExplanation / Answer
Imports System.IO
Public Class Form1
Dim SeatLetters() As String = {"A", "B", "C", "D"}
Dim PlaneData As New DataTable("Flight1")
Dim PlaneGrid As New DataGridView
Dim WaitingList As New ListBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PlaneData.Columns.Add("Row")
PlaneData.Columns.Add("Seat")
PlaneData.Columns.Add("Passenger")
If My.Computer.FileSystem.FileExists(Path.Combine(Application.StartupPath, "PlaneReservations.xml")) Then
PlaneData.ReadXml(Path.Combine(Application.StartupPath, "PlaneReservations.xml"))
Else
For x As Integer = 1 To 10
For y As Integer = 0 To 3
Dim NewRow As DataRow = PlaneData.NewRow
NewRow("Row") = x
NewRow("Seat") = x & SeatLetters(y)
NewRow("Passenger") = "None"
PlaneData.Rows.Add(NewRow)
Next
Next
End If
If My.Computer.FileSystem.FileExists(Path.Combine(Application.StartupPath, "WaitingList.txt")) Then
Using SR As New StreamReader(Path.Combine(Application.StartupPath, "WaitingList.txt"))
While Not SR.EndOfStream
WaitingList.Items.Add(SR.ReadLine)
End While
End Using
End If
With PlaneGrid
.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised
.Location = New Point(8, 8)
.Size = New Size(320, 500)
.AutoSizeRowsMode = _
DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
.ColumnHeadersBorderStyle = _
DataGridViewHeaderBorderStyle.Raised
.CellBorderStyle = _
DataGridViewCellBorderStyle.Sunken
.GridColor = SystemColors.ActiveBorder
.ColumnHeadersDefaultCellStyle.Font = _
New Font(PlaneGrid.Font, FontStyle.Bold)
.RowHeadersVisible = False
.EditMode = DataGridViewEditMode.EditProgrammatically
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.DataSource = PlaneData
End With
AddHandler PlaneGrid.CellClick, AddressOf ChooseSeat
Me.Controls.Add(PlaneGrid)
With WaitingList
.Name = "WaitingList"
.Location = New Point(336, 8)
.Size = New Size(200, 500)
.SelectionMode = SelectionMode.One
End With
AddHandler WaitingList.Click, AddressOf RemoveFromWaitingList
Me.Controls.Add(WaitingList)
End Sub
Private Sub ChooseSeat(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
If PlaneGrid.Rows(e.RowIndex).Cells("Passenger").Value = "None" Then
Dim NewPassengerName As String = InputBox("Enter Passenger Name", "Seat Reservation")
If NewPassengerName <> "" Then
PlaneGrid.Rows(e.RowIndex).Cells("Passenger").Value = NewPassengerName
End If
Else
If MessageBox.Show("This seat has been reserved" _
& vbCrLf _
& "do you want to remove the reservation ?", _
"Seat Reservation", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
PlaneGrid.Rows(e.RowIndex).Cells("Passenger").Value = "None"
Exit Sub
Else
Dim PassengerName As String = InputBox("Enter Passenger Name", "Waiting List Entry")
If PassengerName <> "" Then
WaitingList.Items.Add(PassengerName)
MessageBox.Show("Passenger has beed added to the waiting list", "Seat Reservation")
End If
End If
End If
End Sub
Private Sub RemoveFromWaitingList(ByVal sender As System.Object, ByVal e As System.EventArgs)
If MessageBox.Show("Remove Passenger from waiting list?", "Waiting List", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.OK Then
WaitingList.Items.Remove(WaitingList.SelectedItem)
End If
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
PlaneData.WriteXml(Path.Combine(Application.StartupPath, "PlaneReservations.xml"))
If WaitingList.Items.Count <> 0 Then
Using SW As New StreamWriter(Path.Combine(Application.StartupPath, "WaitingList.txt"))
For Each S As String In WaitingList.Items
SW.WriteLine(S)
Next
SW.Flush()
SW.Close()
End Using
End If
End Sub
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.