Airline reservation system using a self-restructuring binary search tree
Due: 21 Nov 2005
Educational objectives: Experience implementing a self-restructuring
binary search tree class and solving problems using it.
Statement of work: (i) Implement a self-restructuring BST class based on
move-to-root rotations, (ii) implement pre-order traversal on such trees, and (iii) Develop a simple airline reservation software, as
in assignments 1 and 2, but using the above class to store records.
Deliverables: Turn in a makefile
and
all header (*.h) and cpp (*.cpp) files that are needed to build your
software, as described in www.cs.fsu.edu/~asriniva/courses/DS05/HWinstructions.html. Turn in your development log too, which should be a plain ASCII text file called LOG.txt
in your project directory. You will submit all of these using the project5submit.sh
script.
Requirements:
- Create
a subdirectory called
proj5
.
- You
will need to have a
makefile
in this directory. In addition, all the
header and cpp files needed to build your software must be present here, as well as the LOG.txt
file.
- You
should implement appropriate classes for the software. Your code should be well designed and object oriented.
- You should implement a self-restructuring BST class based on
move-to-root rotations. This class need not be generic; it is sufficient
to implement it so that it can store the reservation records. You are free to choose
the specific features you wish to implement, but they should be reasonable. For
example, you will certainly need to implement a method that lets you insert records into the tree.
- Your
software keeps track of reservation records in an object of the class you implemented above. Each record consists of the following
fields: (i) Name, (ii) Phone number, (iii) Flight number, and (iv) Date of travel. The user will enter Name in the following format:
FirstName space [middle initials, if applicable, with a period after each initial] space LastName
.The user will enter Phone number as a sequence of digits, with possibly, spaces, hyphens, and parentheses. All these, except the digits, should be ignored. That is, the number 850-644-1234
is equivalent to the number (850) 644 1234
. The user will enter the flight number as a sequence of alphanumeric characters, without whitespace between them. The user will enter the travel date in one of the following forms: mmddyyyy
or mmddyy
. All
user input will be syntactically correct. The user is provided the ability to perform the operations given below.
- The
software is run by the user on the command
line, as follows:
- The
software reads a list of flights and the number of seats in them from
Filename
(which contains a flight number followed by the number of seats, on each line), stores the information in a suitable container, and then repeats the following:
- It
presents a prompt of the following form: Reservations>>
- It
accepts commands typed by the user (each command is terminated by a newline).
Any leading whitespace (before the command) is ignored.
- It
performs an operation, as desired by the user's command. This operation
may include an output. All output should be on a new line, and should
terminate with a single newline character. You should not output anything other than those specified below.
- The
complete set of commands accepted by your program are as follows. The time complexities of several operation are also specified, with
N
denoting the number of records in the tree, and H
the height of the tree.
new flight <flight-number> <seats>
- where
<flight-number> is the flight number of a new flight to be added, and <seats> is the number of seats in that flight. If a flight with that name already exists, then you should
output the following: A flight numbered <number> already exists. Flight
not created.
quit
- This
causes the program to terminate after de-allocating all memory that was
allocated.
add
(<name>, <phone-number>, <flight-number>, <date>)
- This creates a new reservation record, if an identical record does not already exist, and inserts it into the tree. If an identical record exists (the phone number is not used in comparing records), then you should output: This reservation already exists. If there is no flight numbered <flight-number>, then output: No flight numbered <flight-number> exists. You should find the correct place to insert by comparing with the
name
field. If the name being inserted is < to the value in a node, then it must be inserted in the left subtree. I had originally asked you to check if a sufficient number of seats are available. You no longer need to do that. O(H)
time.
delete <name> from <flight-number> on <date>
- Delete
the corresponding record. If the record does not exist, then output: This reservation does not exist. If the node to be deleted has two children, then swap positions with its predecessor.
O(H)
time.
is
<name> in <flight-number> on <date>?
- Output
Yes if <name> has a reservation on the specified flight. Otherwise
output No. This command also causes a self-restructuring operation using move-to-root rotations, if the reservation exists. Once this command is issued, the only command that may subsequently be issued are
display
and quit. O(H)
time.
lookup
<name>
- Lists all records for <name>, in the following format: 1. (<name1>, <phone-number1>, <flight-number1>, <date1>), 2. (<name2>, <phone-number2>, <flight-number2>, <date2>), ... . If a reservation with that name does not exist,
then you should output: No reservation exists for <name>.
O(H)
time.
display
<flight-number> on <date>
- Display
each record in the specified flight in the order in which they appear in a pre-order traversal of the tree, in the following format: 1. (<name1>, <phone-number1>, <flight-number1>, <date1>), 2. (<name2>, <phone-number2>, <flight-number2>, <date2>), ... . If no record exists for that flight, then output: No reservation exists for this flight. If there is no flight numbered <flight-number>, then output: No flight numbered <flight-number> exists.
O(N)
time.
Sample input file and executable: A sample executable is available on linprog under the directory:
/home/courses/cop4530/fall05/solutions/proj5. It works correctly for the sample input file and commands provided in the same directory.
Bonus points (5):
You may get up to 5 additional points for significant extra work, such as implementing more features, or providing a GUI interface. Please obtain feedback from us prior to doing this. If you wish to get bonus points, then please submit your work as usual, but send an email to the TA. The TA will schedule a meeting with you, and you can demonstrate the special features of your software then.
Notes:
- Your program should not
have any output other than those specified above.
- You may use the STL
string
, map
, pair
, and
vector
classes. Please get my permission before using any
other STL feature.
Last modified: 18 Nov 2005