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:
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.
| |
-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
Style Requirements
Submission
Read and follow the submission instructions when you are ready to submit your lab.
Grading