Download OLA5Description

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Binary search tree wikipedia , lookup

Transcript
Lab 4: Data with Multiple Organizations
Deadline: see calendar
Objective: To gain a deeper understanding of the binary search tree and priority queue (implemented as a heap). To
become familiar with data needing multiple organizations.
Description: We are maintaining a list of patients on a waiting list for a heart donor. Patients with highest priority
(priority 10) are the most critical and will be given a heart first when one becomes available. Patient information
includes the patient’s name, his/her doctor’s name and contact information, and priority number for the patient.
In addition to selecting the next heart donor, the following operations must be done:
 Print a list of donors in alphabetical order by name.
 Delete a donor from the list when a heart is received or if the person is deceased.
 Add a new patient to the list.
 Search the list to determine whether a particular patient is on the list.
 Change a person’s priority (their health may have worsened and they need to go to a higher priority in the
list).
Design: This program requires a data structure that simultaneously supports two different data-management tasks.
Standard priority queue operations are needed to make sure that patients with highest priority are given hearts first.
Secondly, the capability of searching and traversing the data structure by patient name is needed. A straightforward
approach is to use two independent data structures: a heap for priority queue operations, and a binary search tree for
search and traversal. One obvious disadvantage of this scheme is the space needed to store two copies of each
record.
This assignment will take a different approach. A binary search tree will contain patient records, but the priority queue
will contain only pointers to patient records in the binary search tree. That is, each entry of the priority queue points
to the record in the binary search tree for the job at the given heap position. An obvious advantage of storing only
pointers in the heap is that the storage requirements are reduced, since a pointer is likely to be much smaller than a
record. The key for the BST is the patient’s name. Assume no two names are the same.
You can proceed as follows:

Design and implement the class Patient, which contains the patient’s name, his/her doctor’s name and
contact information, and priority number for the patient. You will store instances of this class in the
HeartCandidates class.

Design and implement the class HeartCandidates which contains the data structure for heart transplant
candidates and provides approaches to managing these patients.

Design and implement the class Menu, which provides the program's user interface.

Implement main function.
Provided for your convenience is a templated binary search tree to be used in this assignment. In addition, a project
has been created containing a start for all of the files that need to be created. You will download those files and use
them as your starting point to implement the solution.
Thus your program needs to do the following:
Read patient information from the file patient.dat. Data in the file is in the following format:
Line 1: Patient’s name (string) in the form lastName, firstName
Line 2: Doctor’s name (string) in the same form
Line3: Doctor’s phone # (string)
Line 4: Priority of the patient
Line 5: Next Patient’s name and so on
Next, print a menu:
1.
Print the list of patients in order by name
2.
Search the waiting list to find a patient. Request the patient’s name.
3.
Add a new patient to the list. Read all of the patient’s information
4.
Remove the patient with highest priority. Request the patient’s name.
5.
Remove a patient who has deceased. Request the patient’s name.
6.
Change a person’s priority. Request the patient’s name.
7.
terminate the program.
Get the user’s choice and process it. If the user’s choice is #7, data from the BST should be written back to the file
patient.dat. The order of the data should be preserved (i.e. if Jones, Joe was at the root of the tree before, then
when the data from the file is read a second time, then Jones, Joe should be at the root of the tree again.
Otherwise the BST will be in the form of a linked list.
Downloading files: Go to my web site and download the zip file OLA5.zip to your local folder. Right click the local
copy of OLA5.zip and choose “extract all to OLA5.” from the popup menu. Double click OLA5/OLA5.sln to start Visual
Studio and load all source files of this assignment.
Before turning in this assignment, rename the project file to YourLastNameOLA5. Then eliminate the debug folder, zip
the project and turn in a zipped copy of this assignment to D2L.
Requirements and Suggestions:
1.
You are not allowed to modify the class BinarySearchTree.
2.
The class Patient must provide two public member functions:
1.
string getKey();
This function returns the name of the patient requesting a heart as the key required by the binary
search tree.
2.
int getPriority();
This function returns the priority of the patient in the queue. The priority must be in the range [1,
10] with 10 having the highest priority.
3.
Pay attention to error handling, such as invalid priority, not enough space (in tree or heap) for a new patient,
cannot find a patient with a specific name, etc. Read about exception handling in the book and use the
exception handlers defined to handle exceptions.
4.
Make sure you understand the BinarySearchTree classes. Code from this class is explained in Chapter 10 of
Carrano if you have trouble understanding it on your own. BST code was used in 2170.
5.
In order to implement the command that lists all of the patients in order by name, you need to call the
BinarySearchTree member function: inorderTraverse by passing a function pointer, which points to a function
which prints the contents of a patient record. Check textbook (5th edition) page 529 to page 531.
6.
Remember -- whenever you want to include the definition of templated classes BST or Heap, you have to
include the .cpp files, i.e.
#include “BST.cpp”
#include “Heap.cpp”
7.
The heap implementation used is the array implementation. You have my permission to use code from
Carrano for inserting into or deleting from the heap. Be sure to cite your source.