1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
CSC100 – Lab 6
Value: 75 points
Assignment:
Develop a program that will be used to monitor the flight information at an airport. The
information to be maintained includes:
the carrier (Southwest, United Airlines, Delta...),
flight number,
whether it is an arriving or departing flight,
published arrival or departure time – this is the time promoted when booking flights
(use a 24-hour format; i.e., 2115 is 15 minutes after the 21st hour, or 9:15 p.m.),
actual arrival/departure time - the time updated as the flight gets closer
arrival or departure location (city).
Your program should allow the user to:
1. Add flight information,
2. Delete flight information
3. Display all flights
4. Display all arrival OR all departing flight information
5. Update the actual time of a flight
6. Quit
Program Design Notes:
Create named constants to be used globally (ie. array sizes)
Create a structure to hold flight information for one flight
o Carrier name will not exceed 20 characters
o Flight number will be an integer value not to exceed three digits,
o Arrival will be a char (‘A’- meaning arrival, ‘D’- meaning departure),
o Arrival or Destination City will not exceed 20 characters
o Published time and Actual time will be integers
Divide the tasks into functions. See the structure chart on page 3.
You may use this design or one of your own.
main()
o Declare an array of structures not to exceed 100 records to hold flight information.
o Call readFile, a function to read data from the file into the array of structures
o Display the menu
o Prompt the user for their choice
o Call appropriate function to perform user’s choice
o If the user chooses an option not on the menu,
Throw the input value as an exception that will be caught and displayed in
an error message
o continue repeating until the user chooses option 6
readFile()
o Read the flight information into an array of record structures.
o You will not know how many flights are in the file so you will need a while loop that
uses the eof() file function. Use an index variable to keep track of how many
flights are in the array while reading. This variable will need to be returned to
main()so main()can pass the information to other functions.
o If the data in the file exceeds the size of the array, throw an exception that will
display an error message to alert the user that only the first 100 flights will be used.
The data should be stored in a file called flight.txt
o EXTRA CREDIT: sort the data by published time using the selection sort algorithm
o The input/output files will be in the following format (excluding 4 lines of headings
used for explanation of the data). A sample input file is posted with the assignment.
Carrier Flight Arrival? Arrival/Dest City Pub Actual
Time Time
|
5 spaces 10 spaces
Delta 195#####A##########San Francisco 1427 1427
American 65 D Kansas City 1812 1830
addFlight()
o Prompt the user for the flight number. Using the search()function, verify that the
flight number does not already exist. If it does, throw the flight number as an
exception that will be caught and display an error message.
o Prompt the user for the remaining flight data that is inserted into the first open slot at
the end of the data in the array.
o Make sure to update the variable that holds the number of flights in the array.
o EXTRA CREDIT: after adding the new flight information into the array at the end of
the current data, re-sort the data by published time using the selection sort algorithm
deleteFlight()
o Prompt the user for the flight number. Using the search() function, verify that the
flight number does exist. If it does not, throw the flight number as an exception that
will be caught and display an error message.
o To remove the flight, “shift-left” all the flight information starting with the flight after
the flight to be deleted.
o Make sure to update the variable that holds the number of flights in the array.
displayAllFlights()
o Display all flight information in a table format with column headings.
(printf() is your friend on this one!)
displayADFlights()
o Prompt the user to display either arriving or departing flights.
o Display all flight information in a table format with column headings.
updateFlight()
o Prompt the user for the flight number. Using the search() function, verify that the
flight number does exist. If it does not, throw the flight number as an exception that
will be caught and display an error message.
o Prompt the user for the new actual time to be stored in the array of structures.
writeFlights()
o When the user chooses to exit the program, the updated information should be written
back to the same file, flight.txt. (fprintf() will be your friend here). This file
should be able to be read back in for the next execution of the program.
o CAUTION: While debugging your program, use a different file name for output.
This way, if there is a formatting error, you do not lose the current information stored
in the input file. Once you are sure everything is formatted correctly, change the file
name to flights.txt. Now your program will remember what flights were in the
array when the previous execution was completed.
search()
o Several of the functions need the capability to locate a flight. To avoid duplicating
code, use a search function that can be called whenever needed.
o search() should be given a flight number and return the index of where the flight
number was located in the array. If the flight number is not present, return -1.
|