Write an interactive C++ program that uses the heap implementation of a priority
ID: 3736868 • Letter: W
Question
Write an interactive C++ program that uses the heap implementation of a priority queue to monitor the flow of patients in a large hospital. The program will maintain information about patients, such as, name, address, age, insurance information, telephone number, emergency contact name and telephone number, and description of emergency. The patient will be assigned an account number. Then will assign the patient a priority depending on type of emergency (critical-needs-immediate-attention, critical-does-not-need-immediate-attention, not-critical).
· The program should manage the scheduling of patients into THREE operating rooms. Patients are chosen for the operating room by priority value, and patients with the same priority are served on first-come, first-served basis.
· Your program should allow the user to
o Enter patient information and assign his/her priority
o Add to queue and given an estimate of waiting time
o Remove from queue and be assigned an operating room
o List all patients still waiting in queue by name.
Copy code and Print Screen of output of question to one word document
Explanation / Answer
Code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
//#inlcude <cstring>
using namespace std;
/*
* Node Declaration
*/
struct patient
{
int priority;
int age;
string name;
string address;
string insurance_info;
int tele_num;
string emergency_name;
int emer_tele_num;
string reason;
int account_num;
struct patient *link;
};
/*
* Class Priority Queue
*/
class Priority_Queue
{
private:
patient *front;
public:
Priority_Queue()
{
front = NULL;
}
/*
* Insert into Priority Queue
*/
void insert(string name, int priority,string reason,string address,string insurance_info,int age,int tele_num,string emergency_name,int emer_tele_num,int account_num)
{
patient tmp, q;
tmp = new patient;
tmp->name = name;
tmp->priority = priority;
tmp->reason=reason;
tmp->address=address;
tmp->insurance_info=insurance_info;
tmp->age=age;
tmp->tele_num=tele_num;
tmp->emergency_name=emergency_name;
tmp->emer_tele_num=emer_tele_num;
tmp->account_num=account_num;
if (front == NULL || priority < front->priority)
{
tmp->link = front;
front = tmp;
}
else
{
q = front;
while (q->link != NULL && q->link->priority <= priority)
q=q->link;
tmp->link = q->link;
q->link = tmp;
}
}
/*
* Delete from Priority Queue
*/
void del()
{
patient *tmp;
if(front == NULL)
cout<<"Queue Underflow ";
else
{
tmp = front;
cout<<"Deleted name is: "<<tmp->name<<endl;
front = front->link;
free(tmp);
}
}
/*
* Print Priority Queue
*/
void display()
{
patient *ptr;
ptr = front;
if (front == NULL)
cout<<"Queue is empty ";
else
{ cout<<"Queue is : ";
cout<<"Priority name ";
while(ptr != NULL)
{
cout<<ptr->priority<<" "<<ptr->name<<endl;
ptr = ptr->link;
}
}
}
};
/*
* Main
*/
int main()
{
int choice, priority,age,tele_num,emer_tele_num,account_num;
string name, address, insurance_info, emergency_name, reason;
Priority_Queue pq;
do
{
cout<<"1.Insert ";
cout<<"2.Delete ";
cout<<"3.Display ";
cout<<"4.Quit ";
cout<<"Enter your choice : ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Input the name value to be added in the queue : ";
cin>>name;
cout<<"Enter the reason : ";
cin>>reason;
cout<<"Input the address : ";
cin>>address;
cout<<"Input the insurance_info : ";
cin>>insurance_info;
cout<<"Enter patient's age : ";
cin>>age;
cout<<"Enter patient's tele_num : ";
cin>>tele_num;
cout<<"Input the emergency contact_name : ";
cin>>emergency_name;
cout<<"Enter patient's emer_tele_num : ";
cin>>emer_tele_num;
cout<<"Enter patient's priority : ";
cin>>priority;
cout<<"Enter patient's account_num : ";
cin>>account_num;
pq.insert(name, priority, reason, address, insurance_info, age, tele_num, emergency_name, emer_tele_num, account_num);
break;
case 2:
pq.del();
break;
case 3:
pq.display();
break;
case 4:
break;
default :
cout<<"Wrong choice ";
}
}
while(choice != 4);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.