loading...

CS301 Data Structures Assignment 2 Solution Fall 2014

Problem Statement:

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.
  • 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.
  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.

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.

Solution:

#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
class Patient
{
public:
};
class pqueue
{
int pqueue1[3];
int tpatient;
int rear,front;

public:
pqueue()
{
rear=-1;
front=-1;
}
void add(int x)
{
if(rear >  20)
{
cout “pqueue over flow”;
front=rear=-1;
return;
}
pqueue1[++rear]=x;
cout “added” x;
}
void display()
{
if(rear==front)
{
cout ” pqueue empty”;
return;
}
for(int i=front+1;i<=rear;i++)
cout pqueue1[i]” “;
}
};

main()
{
int i;
char n;
pqueue qu;
while(1)
{   cout”\n=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= M e n u =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=”;
cout “\n1:Rigester new patient   “”\n2:display list of patients treated by physcian A    “”\n3:display list of patients treated by physcian B    “”\n4:Display list of total pateints served “”\n5:Exit”;
cout”\n=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= M e n u =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=\nEnter ur choice”;
cin >> i;
switch(i)
{
case 1:
do{
cout ” Enter Patient name: “;
cin >> name
cout ” Enter patient age: “;
cin>>saba
qu.add(i);
break;
cout”a”endl;
case 2: ;
case 3:  qu.display();break;
case 4: exit(0);
}
}
return (0);
}

DOWNLOAD SOLUTION HERE
loading...