Homework Help

by Matt (no login)

I am having difficulty determining a way to detect when the array is full so that I can place the passenger on the waiting list.
Here is the assignment. Current code is posted at the bottom. Basically I have completed steps (1)a, (1)b, (1)c), (2)a, (2)b, and (3). It is a bit "rookie" but it seems to work so far. (I am also not too happy with the method I used to label the printed array. Suggestions are welcome!)

Airline reservations- Write a reservation system for an airline flight. Assume the airline has 10 rows with 4 seats in each row. Use a 2-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. Display a three-option menu.

(1) Add a passenger to the flight or waiting list
a. Request the passenger's name.
b. display a chart of the seats in the airplane in tubular form.
c. If seats are available, let the passenger choose a seat. Add the passenger to the seating chart.
d. If no seats are available, place the passenger in the waiting list.

(2) Remove the passenger from the flight
a. Request the passengers name.
b. Search the seating chart for the passenger's name and delete it.
c. If the waiting list is empty, update the array so the seat is available.
d. If the waiting list is not empty, remove the first person from the list and give that person the newly vacated seat.

(3) Quit

SCREEN 12
DIM SEAT(10, 4) AS STRING
DIM MENU AS STRING

DECLARE SUB SEATING()
DECLARE SUB ADDPASS()
DECLARE SUB REMOVEPASS()

' **** MENU ****
DO
CLS
PRINT "1) Add passenger to flight or waiting list"
PRINT "2) Remove passenger from flight"
PRINT "3) Exit"
DO
MENU = INKEY$
SELECT CASE MENU
CASE "1" TO "3": EXIT DO
END SELECT
LOOP

SELECT CASE MENU
CASE "1": ADDPASS 'sub
CASE "2": REMOVEPASS 'sub
CASE "3": EXIT DO
END SELECT
LOOP
END

' **** SEATING ARRAY ****
SUB SEATING ()
SHARED SEAT() AS STRING
DIM R AS INTEGER
DIM S AS INTEGER

CLS
FOR R = 1 TO 10
FOR S = 1 TO 4
IF SEAT(R, S) = "" THEN SEAT(R, S) = "'AVAILABLE'"
NEXT S
NEXT R

PRINT "SEATING LIST"
PRINT TAB(10); "SEAT 'A'"; TAB(25); "SEAT 'B'"; TAB(40); "SEAT 'C'"; TAB(55); "SEAT 'D'"
PRINT

FOR R = 1 TO 10
IF R = 1 THEN PRINT "ROW 1 ";
IF R = 2 THEN PRINT "ROW 2 ";
IF R = 3 THEN PRINT "ROW 3 ";
IF R = 4 THEN PRINT "ROW 4 ";
IF R = 5 THEN PRINT "ROW 5 ";
IF R = 6 THEN PRINT "ROW 6 ";
IF R = 7 THEN PRINT "ROW 7 ";
IF R = 8 THEN PRINT "ROW 8 ";
IF R = 9 THEN PRINT "ROW 9 ";
IF R = 10 THEN PRINT "ROW 10 ";

FOR S = 1 TO 4
PRINT SEAT(R, S) + "",
NEXT S
PRINT
NEXT R

FOR R = 1 TO 10
FOR S = 1 TO 4
IF SEAT(R, S) = "'AVAILABLE'" THEN SEAT(R, S) = ""
NEXT S
NEXT R
END SUB

' **** ADD PASSENGER ****
SUB ADDPASS
SHARED SEAT() AS STRING
DIM NM AS STRING
DIM S AS INTEGER
DIM R AS INTEGER
DIM A AS STRING
DIM FOUND AS INTEGER

CALL SEATING
PRINT
DO
INPUT "Enter passenger name (blank to exit): ", NM
IF LEN(NM) = 0 THEN EXIT SUB
INPUT "ENTER DESIRED SEAT: (Row, Seat)", R, S
IF SEAT(R, S) = "" THEN SEAT(R, S) = NM
FOUND = 1
IF FOUND = 0 THEN PRINT "That seat is not available!"
PRINT "Would you like to select another seat? (Y/N)"
DO
A = UCASE$(INKEY$)
LOOP UNTIL A = "Y" OR A = "N"
LOOP UNTIL A = "N"
CALL SEATING
PRINT
PRINT "Press any key to retern to menu"
SLEEP
END SUB

' **** REMOVE PASSENGER ****
SUB REMOVEPASS
SHARED SEAT() AS STRING
DIM NM AS STRING
DIM FOUND AS INTEGER

CLS
PRINT
CALL SEATING
DO
PRINT
INPUT "Enter passenger name (blank to exit): ", NM
IF LEN(NM) = 0 THEN EXIT SUB
FOUND = 0
FOR R = 1 TO 10
FOR S = 1 TO 4
IF UCASE$(NM) = UCASE$(SEAT(R, S)) THEN
FOUND = 1
SEAT(R, S) = ""
PRINT
PRINT "'" + NM + "'" + " was found and removed from the list.": EXIT FOR
PRINT
END IF
NEXT S
NEXT R
IF FOUND = 0 THEN
PRINT
PRINT "'" + NM + "'" + " was not found on the list."
PRINT
END IF
LOOP
END SUB



    
This message has been edited by Solitaire1 on May 19, 2012 8:14 PM

Posted on May 19, 2012, 6:37 PM

Respond to this message   

Return to Index


Response TitleAuthor and Date
Matt: There is text in the above message. Do not use an asterisk.Solitaire on May 19
 RE:MATT on May 19
  * I added more information to the above post. Check it out now.Solitaire on May 19
   reMatt on May 19
    * You can do it! You've got the smarts.Solitaire on May 20
     re:you can do itMatt on May 20
      Something like this:Solitaire on May 20
       AWESOME!MATT on May 20
        oopsMatt on May 20
         Default tab settingsSolitaire on May 20
          RE:default tabMATT on May 20
           Your arrays and the IF block need fixing.Solitaire on May 20
            re:your arrays are..Matt on May 22
             Re: CorrectionMATT on May 22
             Sub can call other subs.Solitaire on May 22
              re: Sub can call..Matt on May 28
            I'm surprised you didn't mention LBOUND and UBOUND.a on May 22