In this case, you will create a Visual Basic solution that allows the Island Breezes Sea Planes airline to assign seats to passengers. This program demonstrates the use of parallel one-dimensional arrays. One array is used to represent the availability of each seat. The other array is used to manage the RadioButton controls on the form. It introduces the technique of using an array of RadioButton objects. Here are instructions on how to design and code this project:
Step 1: Create the Project:
Create a Visual Basic Project using the project name “AirplaneSeating”.
Step 2 – Design the Form:
Design the form as shown in Figure 1. You will need two button controls, one textbox, one group box, eight radio buttons, one picture box, and two label controls.
Step 3 – Declare the form-level arrays:
Declare an array of Boolean values to indicate the availability of each seat:
Private availableSeats(7) As Boolean
Declare an object array as type RadioButton:
Private buttons(7) As RadioButton
Step 3 – Add code in the Form’s Load event to initialize the arrays:
Each object in the buttons array must be initialized to be a RadioButton object. In the Form’s Load event, write a loop to initialize each array element using this syntax:
buttons(i) = New RadioButton
After this loop, load each individual radio button into an array position, using this syntax (in this example, the first
radio button control’s name is seat10ARadioButton, and it is being loaded into the first object array position):
buttons(0) = seat10ARadioButton
Do this for each radio button control.
Finally, write a loop to set the Checked property of all of the buttons array elements to False.
Step 4 – Create a sub procedure for showing seat availability on the form:
Create a sub procedure named UpdateSeatButtons that will loop through the availableSeats array. If an element in the availableSeats array equals False, set the corresponding buttons array element’s Enabled property to False to visually indicate that this seat is no longer available.
Step 5 – Create a function for determining if there are any seats still available:
Create a Boolean function named CheckForAvailable that will loop through the availableSeats array to determine if there are any seats still available. If there is at least one seat available, return a True value; otherwise, return False.
Step 6 – Add code in the Confirm Seat button’s Click event to update the seating chart:
Loop through the buttons array to determine which button was selected. Set the corresponding availableSeats array element to False. Then call the UpdateSeatButtons sub procedure to update the visual seating chart.
Call the CheckForAvailable function to determine whether you should display a message indicating that the flight is full.
Step 7 – Finish up:
Be sure to add the code for the Exit button.
Step 8: Save and run
Save all files, then start the application. Test the program using various selections. Figure 2 shows a sample run of this program, with the user’s choices shown. Notice that the unavailable seats are grayed.
Add a second form to the project that produces a visual “boarding pass”. Design the form to look like a printed boarding pass. Include the passenger name and the seat assignment.
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
This is only a preview of the solution. Please use the purchase button to see the entire solution