Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your main function should create an instance of the PriorityQueue class with the size that is passed in as a command line argument. It should

Your main function should create an instance of the PriorityQueue class with the size that is passed in as a command line argument. It should then repeatedly display a menu to the user, just like in previous labs. The code to print this menu can be written like: cout << "======Main Menu======" << endl; cout << "1. Get Patient Information from File" << endl; cout << "2. Add Patient to Priority Queue" << endl; cout << "3. Show Next Patient" << endl; cout << "4. Treat Next Patient" << endl; cout << "5. Treat Entire Queue" << endl; cout << "6. Quit" << endl; Each option should do the following: 1. Get Patient Information from File This option should ask the user for a filename using the following print statement: cout << "Enter filename:" << endl; It should then read the patient data from that file into the queue based on each patients injury severity. If there are too many patients for the queue to store, it should read as many as it can before printing the following: cout << "Priority Queue full. Send remaining patients to another hospital." << endl; 2. Add Patient to Priority Queue: This option should ask for a new patients name, injury severity, and treatment time, then insert them into the priority queue based on their injury severity. If there is a tie in injury severity, it should prioritize the patient with the lower treatment time. You should use the following print statements to ask the user for information: cout << "Enter Patient Name:" << endl; cout << "Enter Injury Severity:" << endl; cout << "Enter Treatment Time:" << endl; If the priority queue is already full, it should print the following message instead: cout << "Priority Queue full. Send Patient to another hospital." << endl; 3. Show Next Patient This option should print out information on the next patient using the print statements below: cout << "Patient Name: " << patientName << endl; cout << "Injury Severity: " << patientInjurySeverity << endl; cout << "Treatment Time: " << patientTreatmentTime << endl; If the queue is empty, it should print the following instead: cout << "Queue empty." << endl; CSCI 2270 Data Structures - Section 100 Instructor: Shayon Gupta Assignment 8, Oct 2018 4. Treat Next Patient This option should remove a patient from the queue, and print the name of the treated patient as well as the total time spent treating patients. It should use the following format to print: cout<<"Patient Name: "<< patientName << " - Total Time Treating Patients: " << totalTreatmentTime << endl; If the queue is already empty, it should print the following instead: cout << "Queue empty." << endl; 5. Treat Entire Queue This option should treat all the patients until the queue is empty. For each one, it should print the same information as option 4 (Treat Next Patient). If the queue is already empty, it should print the following instead: cout << "Queue empty." << endl; 6. Quit This option should print out the following friendly goodbye, then quit: cout << "Goodbye!" << endl; CSCI 2270 Data Structures - Section 100 Instructor: Shayon Gupta Assignment 8, Oct 2018 To build your queue, you will use the PriorityQueue class defined in the PriorityQueue.hpp header file on Moodle. Visually, the priority queue that this class implements would look like this: This implementation uses an array to store all the values linearly, although the underlying structure can also be thought of as a tree as discussed in class: The class implements the following functions: PriorityQueue::PriorityQueue(int queueSize) The constructor function should dynamically allocate an array to store the patients of size queueSize. This size is passed as a command line argument. PriorityQueue::~PriorityQueue() The deconstructor should free all the memory that the priority queue allocated. CSCI 2270 Data Structures - Section 100 Instructor: Shayon Gupta Assignment 8, Oct 2018 void enqueue(string _name, int _injurySeverity, int _treatmentTime) This function should add a new patient to the appropriate position in the queue, based on their injury severity. If there is a tie in injury severity, it should prioritize the patient with the lower treatment time. It should use the repairUpwards function to accomplish this. void dequeue() This function should remove the patient at the front of the queue. It should use the repairDownwards function to accomplish this. string peekName() This function should return the name of the patient at the front of the queue. int peekInjurySeverity() This function should return the injury severity of the patient at the front of the queue. int peekTreatmentTime() This function should return the treatment time of the patient at the front of the queue. bool isFull() This function should return whether or not the priority queue is full. bool isEmpty() This function should return whether or not the priority queue is empty. void repairUpwards(int nodeIndex) This function should re-order a tree after a new node has been added at index nodeIndex, and do so by swapping that node with its parent until the tree is valid again. void repairDownwards(int nodeIndex) This function should re-order a tree after a node has been removed at index nodeIndex, and do so by swapping that node with one of its children until the tree is valid again.

#ifndef PRIORITYQUEUE_HPP #define PRIORITYQUEUE_HPP #include // a struct to store patient information struct PatientNode { std::string name; int injurySeverity; int treatmentTime; }; class PriorityQueue { public: /* class constructor Purpose: perform all operations necessary to instantiate a class object Parameter queueSize: Maximum size of the priority queue return: none */ PriorityQueue(int queueSize); /* class destructor Purpose: free all resources that the object has acquired Parameters: none return: none */ ~PriorityQueue(); /* Method Name: enqueue Purpose: enqueue new patient into priority queue; call other method(s) as required to maintain heap Parameter: _name - name of patient to be entered in priority queue Parameter: _injurySeverity - severity of injury Parameter: _treatmentTime - time required for doctor to treat patient injury returns void */

void enqueue (std::string _name, int _injurySeverity, int _treatmentTime); /* Method Name: dequeue Purpose: remove the patient at the front of the priority queue from the queue, call other method(s) as required to maintain heap Parameters: none return: void */ void dequeue(); /* Method Name: peekName Purpose: get name of patient at front of priority queue while maintaining encapsulation Parameters: none return: name of patient at the front of the priority queue */ std::string peekName(); /* Method Name: peekInjurySeverity Purpose: get injury severity of patient at front of priority queue while maintaining encapsulation Parameters: none return: injury severity of patient at the front of the priority queue */ int peekInjurySeverity(); /* Method Name: peekTreatmentTime Purpose: get treatment time of patient at front of priority queue while maintaining encapsulation Parameters: none return: treatment time of patient at the front of the priority queue */ int peekTreatmentTime(); /* Method Name: isFull Purpose: indicate if priority queue is full Parameters: none return: true if queue is full, false otherwise */ bool isFull(); /* Method Name: isEmpty Purpose: indicate if priority queue is empty Parameters: none return: true if queue is empty, false otherwise */ bool isEmpty();

private: /* Method Name: repairUpward Purpose: maintain heap properties by swapping node with parent if necessary Parameter nodeIndex - index of node that may violate heap properties return: void */ void repairUpward(int nodeIndex); /* Method Name: repairDownward Purpose: maintain heap properties by swapping node with child if necessary Parameter: nodeIndex - index of node that may violate heap properties return: void */ void repairDownward(int nodeIndex); PatientNode* priorityQueue; //pointer to the array used to implement priority queue int currentQueueSize; //number of patients currently in priority queue int maxQueueSize; //maximum capacity of priority queue }; #endif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

More Books

Students also viewed these Databases questions