EECS 268: Spring 2006

Programming Project 1

Due: Sunday 2/19 2006 at 11:59pm

Project Objective

To practice abstraction, recursion, automated unit-testing, and creation of a basic List ADT.

Instructions

Implement a simple airline flight scheduling system that reads a schedule of flights from a file, stores the flights in sorted order by flight departure time, and allows the user to print flight schedules in several orders. Define a class Flight with instance variables to store:

  1. Flight number.
  2. Departure time which is an int in military time (e.g. 730 for 7:30am, 1417 for 2:17pm).
  3. Arrival time which is an int in military time (e.g. 730 for 7:30am, 1417 for 2:17pm).
  4. Departure city code which is a three character string (e.g. DFW).
  5. Arrival city code which is a three character string (e.g. DFW).

Define a class Schedule that contains an array of Flight objects stored in ascending order by flight departure time. When flights are added to the Schedule, they should be inserted in sorted order so you never actually call a sort function. Similarly removing a flight, and all other methods for that matter, should always preserve the sorted order of flights.

The following table describes a minimum set of methods that you must implement. All methods marked as Recursive must be implemented to accomplish their primary purpose with direct (function calls itself) or indirect (function calls a direct recursive function or original function recursively) recursion. You may implement additional methods as needed.

Schedule
-flights Array of MAXSIZE Flights.
-size Number of Flights currently in flights.
-MAXSIZE static constant number of possible flights, no less than 20.
+Schedule() Default constructor.
+insert(in newFlight: Flight): void Insert newFlight in flights in ascending sorted order by Flight departure time.
+remove(in remFlight: Flight): void Remove remFlight from flights, preserving ascending sorted order by Flight departure time.
+getLength(): integer {query} Return the number of Flights in flights (this is not the same as MAXSIZE unless flights is full).
+find(in flightToFind: Flight): Flight {query} Return the Flight from flights with the same departure time as flightToFind. Recursive Binary Search
+findAfter(in time: int): Flight {query} Return the Flight from flights with the departure time equal to or closest after time. Recursive Binary Search (Modified)
+outputAsc(): void {query} Print the Flights in flights to standard output in ascending order by departure time. Recursive
+outputDesc(): void {query} Print the Flights in flights to standard output in descending order by departure time. Recursive
+outputClosest(): void {query} Print the Flights in flights to standard output in closest-outward order by departure time (as described below). Recursive

In an input file, a sequence of commands will be given with one command per line. You should implement a UI class that processes the following commands:

I num departTime arriveTime departCity arriveCity // insert a new flight
R departTime // remove a flight with given departure time
F departTime // find and output info on flight with given departure time
T departTime // find and output info on flight closest after given departure time
A            // output info on all flights in schedule in ascending order
D            // output info on all flights in schedule in descending order
C time       // output info on all flights in schedule in "closest-outward order"
             // closest-outward order means print the closest flight at or after a given time then output the flight before it then the flight after it,
             // working its way out (further away from the given time) in an alternating before/after fashion.

Sample input file:

I 17 730 912 MCI DFW
I 22 742 927 DEN LAX
I 4 612 849 HOU SEA
I 153 1417 1539 ORD SFO
I 29 539 756 DFW HNL
I 297 657 935 DEN FAT
A
D
C 700
C 735
R 730
A
F 657
F 730
T 1200
T 1500
C 612

Sample output to be written to standard out:

Ascending Order:
Flight # 29 from DFW departs 539 to HNL arrives 756
Flight # 4 from HOU departs 612 to SEA arrives 849
Flight # 297 from DEN departs 657 to FAT arrives 935
Flight # 17 from MCI departs 730 to DFW arrives 912
Flight # 22 from DEN departs 742 to LAX arrives 927
Flight # 153 from ORD departs 1417 to SFO arrives 1539

Descending Order:
Flight # 153 from ORD departs 1417 to SFO arrives 1539
Flight # 22 from DEN departs 742 to LAX arrives 927
Flight # 17 from MCI departs 730 to DFW arrives 912
Flight # 297 from DEN departs 657 to FAT arrives 935
Flight # 4 from HOU departs 612 to SEA arrives 849
Flight # 29 from DFW departs 539 to HNL arrives 756

Closest Order:
Flight # 17 from MCI departs 730 to DFW arrives 912
Flight # 297 from DEN departs 657 to FAT arrives 935
Flight # 22 from DEN departs 742 to LAX arrives 927
Flight # 4 from HOU departs 612 to SEA arrives 849
Flight # 153 from ORD departs 1417 to SFO arrives 1539
Flight # 29 from DFW departs 539 to HNL arrives 756

Closest Order:
Flight # 22 from DEN departs 742 to LAX arrives 927
Flight # 17 from MCI departs 730 to DFW arrives 912
Flight # 153 from ORD departs 1417 to SFO arrives 1539
Flight # 297 from DEN departs 657 to FAT arrives 935
Flight # 4 from HOU departs 612 to SEA arrives 849
Flight # 29 from DFW departs 539 to HNL arrives 756

Ascending Order:
Flight # 29 from DFW departs 539 to HNL arrives 756
Flight # 4 from HOU departs 612 to SEA arrives 849
Flight # 297 from DEN departs 657 to FAT arrives 935
Flight # 22 from DEN departs 742 to LAX arrives 927
Flight # 153 from ORD departs 1417 to SFO arrives 1539

Found flight:
Flight # 297 from DEN departs 657 to FAT arrives 935

No flight found with departure time 730

Found flight:
Flight # 153 from ORD departs 1417 to SFO arrives 1539

No flight found after departure time 1500

Closest Order:
Flight # 4 from HOU departs 612 to SEA arrives 849
Flight # 29 from DFW departs 539 to HNL arrives 756
Flight # 297 from DEN departs 657 to FAT arrives 935
Flight # 22 from DEN departs 742 to LAX arrives 927
Flight # 153 from ORD departs 1417 to SFO arrives 1539

General Requirements

  1. Your input/output formats must match the examples given above exactly
  2. You may not use any global variables.
  3. Each class must be defined with a pair of files: a header file describing the methods and instance variables, and a c++ file with the implementations.
  4. Only header files may be #include-ed. Each c++ source file must be separately compiled via directives in your makefile.
  5. All instance variables in all classes must be declared private.
  6. The friend keyword cannot be used.
  7. Your program must use argc/argv to take a single argument, the input file.
  8. Name your executable "flights"
  9. You must use the recursive binary search algorithm in find() and a slightly modified version of the recursive binary search algorithm in findAfter().
  10. You should develop this program in a test-first or a test-last manner as described in Lab 3. You may choose which approach you use, but use the approach throughout the development of the project. If you don't care which approach you use, choose test-first if your KUID starts with an odd number and use test-last if your KUID starts with an even number. Indicate which approach you used by adding TL or TF to your project submission tar file.
  11. Keep track of the time you spend on this project and send the total in the project submission email.

Style Requirements

  1. Your code must be well modularized. Your main function should simply call a couple other functions; they in turn should be well modularized. (See the Modularity section on pages 27-28 of the text and follow those guidelines.)
  2. You must use an appropriate documentation style, including comments describing the purpose of methods and in-line comments. (See, for example, the "Key Concepts" section on page 43 of the text.)
  3. Follow the code paragraphing conventions summarized on pages 40-42 of the text.

Submission

Read and follow the submission instructions when you are ready to submit your lab.

Grading