Suppose in a Hospital, there are two physicians to deal with patients. Patients of all ages come for their check up. Physician ‘A’ is designated as physician of old patients while physician ‘B’ has to check other patients. Many patients come to the hospital at the same time. There are two queues of patients against each physician. If patient is an old man, he will stand in second queue; otherwise he will stand in first queue. Both doctors check their patients one by one on first come first served basis. Due to timing restriction of the hospital, each doctor can check a maximum of 20 patients per day.
You are required to write a program in C++ to implement the above scenario. It should be clear that patients will be added on back/rear side of the queue and will be served from front of the queue. Further, your program should use array to implement above scenario.
Model of one of the patients’ queues (array part) is given below.
Solution Guidelines:
You are required to implement queue as an array.
Your solution should contain two classes Patient class and PatientQueue class.
Patient class should be able to set patients’ information given in above model.
Further, your program should implement the following operations for PatientQueue class / data structure.
1. Add_Patient() : add new patient in the queue
2. Display_Patient_Phy1() : Show all Patients information treated by Physician A.
3. Display_Patient_Phy2() : Show all Patients information treated by Physician B.
4. Total_Patients() : Show the total number of patients served on a particular day.
In main() function, you have to create two patient queues; one to store records of old patients, and one to store record of other patients.
Each queue should be populated based on age factor; for example if age is less than 50, patient should be added in first queue otherwise in second queue.
Hint: Array index should hold Patient type object. In case of integer type array, you store an integer type data on array index. Here, as you have to store patient type data in array (queue), so patient object will be added on array index.
Sample Output:
For sample output, see the attached .GIF file.
Please post what you have tried, post anything you are having difficulties with, and post any questions you have. We don't know what you have tried so we can't help you until you help us understand what you need help with.
This isnt final code gives some errors.
#include<iostream>
#include<string>
#include<conio.h>
#include<stdlib.h>
# define MAX 20
using namespace std;
int queue[MAX];
int front = -1;
int back = -1;
int rear = -1;
void insert(int element){
if (rear == MAX - 1){ printf("\nTHe Queue is full\n"); return; }
if (front == -1){ front = 0; }
rear = rear + 1;
queue[rear] = element;
}
int del(int element){
if (front == -1 || front == front + 1){ printf("\nThe queue is empty\n"); return element; }
element = queue[front]; front = front + 1; printf("%d Element Deleted", element); return element;}
#include<iostream>
#include<string>
#include<conio.h>
#include<stdlib.h>
# define MAX 20
usingnamespace std;
int queue[MAX];
int front = -1;
int back = -1;
int rear = -1;
void insert(int element){
if (rear == MAX - 1){ printf("\nTHe Queue is full\n"); return; }
if (front == -1){ front = 0; }
rear = rear + 1;
queue[rear] = element;
}
int del(int element){
if (front == -1 || front == front + 1){
printf("\nThe queue is empty\n");
return element;
}
element = queue[front]; front = front + 1;
printf("%d Element Deleted", element);
return element;
}
void disp(){
for (int i = front; i<=rear; i++){
printf("%d", queue[i]);
}
}
int main(){
int choice = 1; int num; string sam = "y";
while (sam=="y"||sam=="Y"){
printf("\n Enter your choice\n");
printf("\n1 Innsert \n ");
printf("\n2 Delete \n ");
printf("\n3 Display \n ");
printf("\n4 Exit \n ");
switch (choice){
case 1:
printf("Enter a number to be inserted\n");
cin >> num;
insert(num);
break;
case 2:
printf("Enter number that you want to delet");
break;
case 3:
disp();
break;
case 4:
exit(1);
break;
default:
printf("\nINVALID CHOICE\n");
printf("");
}
cout "\nFor another operation Enter Y for Quit enter N\n";
cin >> sam;
}
system("pause");
return 0;
}
Next time put your codes inside a code block to be more readable:
1 2 3
[code]
...put all your codes here
[/code ]
You can click on the available format at the right of this text box when you want to reply. Click on the icon <> and the tags will be inserted for you. Just put all your codes in the middle of the open and close "code" tags