Question
PROJECT DESCRIPTION: Document a Visual Basic program that creates a seating chart for a theater. The number of rows and seats can be adjusted depending
PROJECT DESCRIPTION:
Document a Visual Basic program that creates a seating chart for a theater. The number of rows and seats can be adjusted depending on the performance. Prices for the seats depend on whether the seat is a reserved seat or a standard seat.
A customer's name must be entered and then the customer can purchase one or more seats. A new receipt is generated each time the customer name is changed.
Once a seat has been purchased, the sales clerk can use the mouse to hover over the seat to determine who the seat belongs to.
BUILD THE PROJECT:
Create a Visual Basic "Windows Forms Application". View the Form1.vb code. Replace the lines of code for Form1 that was created by Visual Studio with the code that is supplied on the class website.
Test the program by entering a customer name and selecting several seats. Then enter a new customer name and select several more seats. Try to purchase a seat that has already been sold.
Use the mouse to hover over a seat that has already been sold to see the customer's name.
LAB REPORT: ANY ONE CAN HELP ME ANSWER THIS 10 QUESTIONS. THANK YOU
1.InputBoxes are used when the program starts to get the number of number, types and prices for the seats. Instead of using InputBoxes, what other method could be used to get the same information?
2.A GroupBox is used to hold the Labels that are used to show each seat in the theater. When the GroupBox is created, its size is set to 422 by 306. These are hard coded numbers in the program. What is the advantage or disadvantage of using numbers such as 422 and 306?
3. A TextBox is used for inputting the customer's name. When the TextBox is created in the CreateControlsOnTheForm subroutine, there is a line that starts with AddHandler. What is this line used for?
4. The number of seats per row is limited to 10 seats. How would the program need to be modified to provide more seats per row?
5. Seats on the first row are identified as A1, A2, A3, A4, etc. Seats on the second row are identified as B1, B2, B3, etc. How does the program put the seat identifier (A1, A2, etc.) in the Text property for each seat when the seats are being created?
6. When a customer wants to purchase a seat, how does the program determine if a seat has already been purchased?
7. When a customer wants to purchase a seat, how does the program determine the price of that seat?
8. What is the Visual Basic Tag property and how is it used to keep track of who purchased a seat?
9. Why is it necessary to detect that the mouse has moved away from the seat when displaying the buyer's name?
10. A ListBox is used to keep track of all seats sold for each customer. How is the ListBox updated when a new customer name is entered?
Here is the code provided:
Public Class Form1 Dim SeatsSelectedByCustomer As Integer = 0 Dim CustomerBill As Decimal = 0 Dim GrandTotal As Decimal = 0
' Create fonts used in the program Dim EnabledFont As Font = New Font("Microsoft Sans Serif", 8, FontStyle.Bold) Dim DisabledFont As Font = New Font("Microsoft Sans Serif", 8, FontStyle.Regular) Dim TitleFont As Font = New Font("Microsoft Sans Serif", 20, FontStyle.Bold)
' Controls on the form Dim lblTitle As Label ' title at the top of the form Dim lblCustomer As Label ' "Customer Name" Dim txtCustomerName As TextBox ' location to enter the cutomer's name Dim lblGrandTotal_ID As Label ' "Grand Total Sales" Dim lblGrandTotal As Label ' location to display the grand total sales Dim lstReceipt As ListBox ' location to display the receipt Dim grpSeats As GroupBox ' used to display all the seats Dim lblShowBuyer As Label ' used to display name of person who purchased a seat
Dim PriceReservedSeat As Decimal = 24D Dim PriceGeneralAdmission As Decimal = 18D
Const minNumberOfRows As Integer = 4 Dim NumberOfRows As Integer = 8 Const minSeatsPerRow As Integer = 5 Dim ReservedRows As Integer = 2 Dim SeatsPerRow As Integer = 10 Const SeatWidth As Integer = 40 Const SeatHeight As Integer = 30 Dim FirstSeatX As Integer = -40 Dim FirstSeatY As Integer = 8
Private Sub frmTheaterSeating_Load(sender As Object, e As EventArgs) Handles MyBase.Load CreateControlsOnTheForm() ' Title, GroupBox for seats, Customer input, Sales receipt, Sales total CreateSeats() ' put seats in the group box End Sub
Public Sub CreateControlsOnTheForm() ' Set Properties for the main form Me.Width = 660 Me.Height = 500 Me.Text = "Theater Seating" ' title bar
' Use a Label for the title at the top of the form lblTitle = New Label lblTitle.Location = New Point(47, 14) lblTitle.Text = "Theater Seat Sales" lblTitle.Font = TitleFont ' Font size = 20, Bold lblTitle.AutoSize = True Me.Controls.Add(lblTitle) ' place the Label on the form
' Use a Label to prompt for the Customer Name lblCustomer = New Label lblCustomer.Location = New Point(33, 61) lblCustomer.Text = "Customer Name" lblCustomer.AutoSize = True Me.Controls.Add(lblCustomer) ' place the Label on the form
' Use a TextBox to input the Customer Name txtCustomerName = New TextBox txtCustomerName.Location = New Point(159, 55) txtCustomerName.Width = 193 txtCustomerName.Height = 27 txtCustomerName.Text = "" txtCustomerName.AutoSize = True Me.Controls.Add(txtCustomerName) ' place the TextBox on the form AddHandler txtCustomerName.MouseClick, AddressOf txtCustomerName_MouseClick
' Use a Label to identify the Grand Total Sales lblGrandTotal_ID = New Label lblGrandTotal_ID.Location = New Point(37, 400) lblGrandTotal_ID.Text = "Grand Total Sales" lblGrandTotal_ID.AutoSize = True Me.Controls.Add(lblGrandTotal_ID) ' place the Label on the form
' Use a Label display the numeric value of the total sales lblGrandTotal = New Label lblGrandTotal.BorderStyle = BorderStyle.Fixed3D lblGrandTotal.Location = New Point(198, 400) lblGrandTotal.Width = 93 lblGrandTotal.Height = 30 lblGrandTotal.Text = "$0.00" lblGrandTotal.TextAlign = ContentAlignment.MiddleRight lblGrandTotal.AutoSize = True Me.Controls.Add(lblGrandTotal) ' place the Label on the form
' Use a ListBox to show the receipt lstReceipt = New ListBox lstReceipt.Location = New Point(426, 19) lstReceipt.Size = New Size(642, 491)
' GroupBox to hold the seats grpSeats = New GroupBox grpSeats.Location = New Point(-2, 88) grpSeats.Width = 422 grpSeats.Height = 306 Me.Controls.Add(grpSeats)
' ListBox to show the receipt for each purchase lstReceipt = New ListBox lstReceipt.Location = New Point(426, 19) lstReceipt.Width = 204 lstReceipt.Height = 420 Me.Controls.Add(lstReceipt)
' Create the label that shows the Buyer of a seat when the mouse moves over the seat lblShowBuyer = New Label lblShowBuyer.BackColor = Color.DarkGreen lblShowBuyer.BorderStyle = BorderStyle.FixedSingle lblShowBuyer.ForeColor = Color.White lblShowBuyer.AutoSize = True lblShowBuyer.Visible = False lblShowBuyer.Height = 22 Me.Controls.Add(lblShowBuyer) AddHandler lblShowBuyer.MouseHover, AddressOf MouseHover_ShowBuyer AddHandler lblShowBuyer.MouseLeave, AddressOf MouseLeave_ShowBuyer End Sub
Public Sub CreateSeats() ' get the number of seats, rows and price for the seats GetEventInfo()
' Create the seats Dim NewSeat As Label Dim row As Integer Dim seat As Integer Dim seatName As String = "A1"
For row = 0 To NumberOfRows - 1 For seat = 0 To SeatsPerRow - 1 NewSeat = New Label ' use a LABEL for each seat NewSeat.Location = New Point(FirstSeatX + SeatWidth * seat, FirstSeatY + SeatHeight * row) NewSeat.Width = SeatWidth NewSeat.Height = SeatHeight If row < ReservedRows Then ' the first few rows are for reserved seats NewSeat.BackColor = Color.LightGreen Else NewSeat.BackColor = Color.LightBlue End If ' set the properties for the label used to display a seat NewSeat.AutoSize = False NewSeat.BorderStyle = BorderStyle.Fixed3D seatName = Chr(Asc("A"c) + row) & (seat + 1).ToString NewSeat.Text = seatName NewSeat.TextAlign = ContentAlignment.MiddleCenter NewSeat.Font = EnabledFont ' add a CLICK event and mouse hover handler and add the label to the form AddHandler NewSeat.Click, AddressOf PurchaseSeat AddHandler NewSeat.MouseHover, AddressOf MouseHover_ShowBuyer AddHandler NewSeat.MouseLeave, AddressOf MouseLeave_ShowBuyer Me.grpSeats.Controls.Add(NewSeat) Next seat Next row txtCustomerName.Focus() End Sub
Private Sub GetEventInfo() Try NumberOfRows = CInt(InputBox("Number of Rows 4-10)", "Number of Rows", "8")) ReservedRows = CInt(InputBox("Number of Reserved Rows", "Reserved Rows", "2")) SeatsPerRow = CInt(InputBox("Seats per Row (5-10)", "Seats per Row", "10")) PriceReservedSeat = CDec(InputBox("Reserved Seat Price (min $15.00)", "Reserved Seat Price", "15.00")) PriceGeneralAdmission = CDec(InputBox("General Admission Price (min $10.00)", "General Admission", "10.00"))
If NumberOfRows < minNumberOfRows Or NumberOfRows > 10 Then MessageBox.Show("Illegal number of rows") ElseIf ReservedRows > NumberOfRows Then MessageBox.Show("Reserved rows can not be greater than the number of rows") ElseIf SeatsPerRow < minSeatsPerRow Or SeatsPerRow > 10 Then MessageBox.Show("Illegal Number of seats per row") ElseIf PriceReservedSeat < 15D Then MessageBox.Show("Illegal price for reserved seats") ElseIf PriceGeneralAdmission < 10D Then MessageBox.Show("Illegal price for general admission seats") ElseIf PriceGeneralAdmission > PriceReservedSeat Then MessageBox.Show("General admission can not be more expensive than reserved seats") Else ' center the array of seats on the form FirstSeatX = 18 + (10 - SeatsPerRow) / 2 * SeatWidth End If Catch ex As Exception MessageBox.Show("Check for empty or illegal values") End Try End Sub
Private Sub PurchaseSeat(sender As Object, e As EventArgs) Dim PriceOfSeat As Decimal If txtCustomerName.Text = "" Then MessageBox.Show("Enter a customer name before continuing") Else Dim seat As Label = sender
If seat.ForeColor <> Color.Gray Then ' this seat is available if it is not grayed out ' If starting a new customer, put customer name at the top of the receipt If SeatsSelectedByCustomer = 0 Then ' customer has not selected any seats yet lstReceipt.Items.Insert(0, "") ' blank line between customers lstReceipt.Items.Insert(0, txtCustomerName.Text) ' new customer name End If
' get the seat information from the selected label seat.Font = DisabledFont ' this seat can no longer be clicked seat.Tag = txtCustomerName.Text ' use the Tag property to put the customer's name on the seat seat.ForeColor = Color.Gray ' gray seat ID out to indicate it is no longer available
' determine the price of the seat based on the background color If seat.BackColor = Color.LightGreen Then PriceOfSeat = PriceReservedSeat Else PriceOfSeat = PriceGeneralAdmission End If
' update and display the bill CustomerBill += PriceOfSeat GrandTotal += PriceOfSeat lblGrandTotal.Text = GrandTotal.ToString("C")
' update the receipt SeatsSelectedByCustomer += 1 ' location in the ListBox to enter the purchase of the seat lstReceipt.Items.Insert(SeatsSelectedByCustomer, seat.Text & " " & PriceOfSeat.ToString("C") & " Total = " & CustomerBill.ToString("C")) End If End If End Sub
Private Sub MouseHover_ShowBuyer(sender As Object, e As EventArgs) ' get the seat information from the selected label Dim seat As Label = sender If seat.Tag <> "" Then lblShowBuyer.Text = seat.Tag ' get the name of the buyer from the Tag property lblShowBuyer.Visible = True lblShowBuyer.Location = New Point(seat.Location.X + SeatWidth - 10, seat.Location.Y + 80) lblShowBuyer.BringToFront() End If End Sub
Private Sub MouseLeave_ShowBuyer(sender As Object, e As EventArgs) lblShowBuyer.Visible = False End Sub
' Prepare for a new customer when the user clicks the Customer Name TextBox Private Sub txtCustomerName_MouseClick(sender As Object, e As MouseEventArgs) If SeatsSelectedByCustomer <> 0 Then ' start a new customer SeatsSelectedByCustomer = 0 CustomerBill = 0D txtCustomerName.Text = "" txtCustomerName.Focus() End If End Sub
End Class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started