![]() |
CSE 143 Summer 2001Homework 3Due: Electronic submission by 9:30 pm, Wednesday July 25. Paper receipt and written report due in quiz section on Thursday July 26. |
For this assignment, you will be leaving the world of word processing behind to begin a new career in airline booking. You will write a program capable of accepting departure and arrival information from the user and displaying a list of possible flights meeting those criteria.
As with all assignments, please read the instructions all the way through before beginning. Read them once again before you turn in your assignment, to be sure you've left nothing out.
The goal of this assignment is to gain experience with the following concepts:
This program maintains a database of airline flight information and allows the user to make queries into this database to find flights which match their desired specifications. Each entry in the flight database contains the following elements.
The data type used to specify the above values is ultimately up to you, however as a suggestion, using a string for all values other than the price is a good option.
When the program starts, the database is initially empty. The program should repeatedly present the user with a menu of possible commands, then accept a command and carry it out. This continues until the user stops the program by entering a quit command.
The available commands are indicated by a letter, which can be either upper or lower case. The available commands are:
After the user enters a command letter, the command should be processed as described in the following sections. Once the command is processed, if the command was anything other than quit, the program should request a new command and continue.
When the user selects this option, the program should prompt for a file name and try to open that file. If it fails, it should report an error and return to the main menu.
Upon successfully opening the file, the program should read the flight information from it and merge this information into the database (more about that below). The file is composed of blocks of 7 lines each, in the following order:
Flight# Departure Location Arrival Location Departure Time Arrival Time Departure Date Price
There might be any number of such blocks, including none, and there is no limit on how many blocks the file may contain. The end of the input is marked by an empty line where the next Flight # would normally be, and the program should stop reading data at that point. You should assume that the input is clean. E.g. You do not need to check for errors in the input file. An example is given below.
All flight data from the file should be “merged” into the existing database. This means:
A flight is said to be in the database if the database already contains an entry with the same Flight#. Different flights may have the same departure or arrival location, same departure or arrival time, same departure date, or same price, but the Flight# is guaranteed to be unique.
Example File
1243A Seattle Omaha 09:00 11:30 09/01/2001 420.00 1488Q San Francisco San Jose 12:30 13:00 10/15/2001 140.99 1003B Seattle Omaha 18:40 21:00 09/01/2001 210.00
When the user selects this option, the program should display a list of all current flights and prompt the user to select a flight to cancel. The selected flight should be removed from the database and its memory de-allocated. The program should then prompt the user for another flight to cancel until -1 is entered, which should return the user to the main menu.
When the user selects this option, the program should ask for three pieces of information from the user.
The program should next use the overloaded operator== to find all flights which match those criteria from the database and display them in order of increasing price (least expensive first), preceded by a number. An example output for Seattle --> Omaha might be:
1. Flight Number : 1003B
Total Price : $210.00
2. Flight Number : 1243A
Total Price : $420.00
After displaying the basic flight information, the program should request that
the user select one of the flights listed by entering the number to the left of
the flight. When a flight is selected the program should then print out
all pertinent information about that flight : Number, Arrival/Departure City,
Arrival/Departure Time, Departure Date, and Price.
Redisplay the initial flight list and prompt the user for another flight. Repeat this process until the user enters -1, at which point the program should return to the main menu.
Exit the program. Make sure that you clean up all dynamically allocated memory before the program actually terminates.
The main technical goal of this assignment is to learn to use classes that have dynamically allocated data structures. Specifically, the database of Flight information should automatically grow as needed. The database should be implemented as a class that contains a dynamic array of flights (flight records being instances of another class). The database class should have at least the following functionality:
The flight class should have at least the following functionality:
You will need to add additional operations to this class, of course, to implement the rest of the program.
As is usually the case, you will find it very helpful to do some designing before you start writing detailed code. What is the high-level structure of the code? What sort of data structure operations are needed to process the various commands?
A few specific suggestions and reminders:
Think about interesting test cases for your program. A few suggestions (by no means a complete list!):
You know the drill by now: planning, implementation, testing, what you’ve learned.
Note: When describing the implementation, please don’t repeat stuff that is already documented in the code. Instead, describe what was problematic or interesting in your implementation, and how you handled these cases.
There is no sample program for this assignment. In cases where the specification is not clear, you may need to make some reasonable assumptions. Feel free to discuss issues about the specifications on the course newsgroup, in sections, with your colleagues, etc.
When you've finished your program, turn in the program code (.cpp and .h files only) using the turn-in form. Print out the receipt that appears, staple it and your written report together, and hand it in during quiz section.