Simulate a patient’s lines using queues with enqueue ( ), dequeue ( ) and printQueue ( ) operations. Define a queue node in the following manner:

typedef struct queueNode { int patientID; // Unique identifier; starts at 1; after 24 hours should be reset to 1 int checkupTime; // Random time; int totalTime; // totalTime = checkupTime + sum of checkupTimes of patients in line //before this patient; units in minutes struct queueNode *pNext; } QueueNode;

 You will randomly generate arrival times and checkup times of patients such that patients arrive every one to five minutes and their checkup times vary from one to five minutes. As patients arrive into the line print out a message indicating that patient has arrived in the line, along with the overall corresponding arrival time and patient ID.  When a patient has finished checkup, print out a message indicating patient ID and totalTime in the line. Simulation should run for k unit time which may be input from user.  The flow of program is as follows:  Generate a random number between 1 – 5 which represents the arrival time of the first patient. Set the variable for total time elapsed to 0.  As more patients arrive, randomly generate a checkup time. Start processing the patients based on checkup time.  Randomly generate the arrival time of the next patient.  Elapsed time should be updated by one unit.  As each minute elapses, a new patient may arrive and/or another patient may be done checkup. Display the messages as described above.  Print out the entire queue for line after every 20 mins.  Repeat steps 2 through 6 for k minutes of simulation.
Hints: In this simulation one minute is really one unit of time. You can increment an integer variable to represent one minute of time elapsing.

any help or how to go about the above given problem...
will be grateful

## All 4 Replies

What do you need help with? Your instructor gave you how the program should function and work. Is there a part you don't understand?

``````#include <iostream>
#include <conio.h>
#include <string>
#include <cstdlib>
#include <time.h>
#include <Windows.h>
using namespace std;

class queue{
private:
typedef struct Node{
int patientid;
int checkuptime;
int totaltime;
Node *next;
};
int arrivaltime;
public:
queue();
void enque();
void deque();
void display();
void arrive();
void timeque();

};
int num,k=0,tempnum,id=1,sum=0,ownarrivaltime=0;
void queue::timeque(){
int timeinque=0;
timeinque=temp->totaltime-sum-ownarrivaltime;
cout<<"timeinque : "<<timeinque<<endl;
}
void queue::arrive(){
int time=0,timer=0;
for(time=0;time<=100;time++){

ownarrivaltime=rand()%5+1;
sum=sum+ownarrivaltime;
if(ownarrivaltime==1){

enque();

}

if(front!=NULL){ timer++;
if(timer==front->totaltime){
deque();
timer=0;
}

}
if(time==100){
deque();
}

}

}
queue::queue(){
front=NULL;
rear=NULL;
arrivaltime=0;
}
void queue::enque(){
int j;
if(front==NULL){ k=0; };
if(k==0){
ptr=new Node;
// data in node

ptr->patientid=id;
j=rand()%5+1;
ptr->checkuptime=j;
ptr->totaltime=ptr->checkuptime;
num=ptr->totaltime;
//data ended
front=ptr;
rear=ptr;
ref=ptr;
ptr->next=NULL;
cout<<"p_id : "<<ptr->patientid;
cout<<" c_time : "<<ptr->checkuptime;
cout<<"   t_time : "<<ptr->totaltime;
id++;
k++;
}
else
{

ptr=new Node;

ptr->patientid=id;
j=rand()%5+1;
ptr->checkuptime=j;
ptr->totaltime=ptr->checkuptime+num;
num=ptr->totaltime;

ptr->next=NULL;
rear->next=ptr;
rear=ptr;
cout<<"p_id : "<<ptr->patientid;
cout<<" c_time : "<<ptr->checkuptime;
cout<<"   t_time : "<<ptr->totaltime;
id++;
k++;
}

cout<<endl;
}
void queue::deque(){
int count=1;
int c_time;

if(front->next!=NULL){
temp=front;
c_time=temp->totaltime;
front=front->next;
front->totaltime=(front->totaltime)- c_time;

cout<<" deleted patient is : "<<temp->patientid<<endl;
cout<<" patient time in que : "<<temp->totaltime<<endl;
cout<<" ******&&&&&&&&**********"<<endl;
temp->next=NULL;
timeque();
delete temp;
}
if(front->next==NULL){
temp=front;
temp->next=NULL;
front=NULL;
cout<<" deleted patient is : "<<temp->patientid<<endl;
cout<<" patient time in que : "<<temp->totaltime<<endl;
cout<<" ******&&&&&&&&**********"<<endl;
tempnum=temp->totaltime;
timeque();
delete temp;

}

}
void queue::display(){
int p=0;
for(p=0;p<=20;p++){
enque();
}
temp=front;
while(temp!=NULL){
cout<<"p_id : "<<temp->patientid;
cout<<"   c_time : "<<temp->checkuptime;
cout<<"     t_time : "<<temp->totaltime<<endl;
temp=temp->next;

}

}

int main(){
queue q;
q.arrive();
_getch();
return 0;
}
``````

// need help to correct code

Yes? And what errors are you getting? Compiler errors, or runtime errors? Show the output. Asking us to analyze 167 lines of beginner code is asking a bit much...

can someone tell me how to do simultaneously enqueue and dequeue in terms of the arrival time of patient and their check up time

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.