Structute Using c++ Queue  The Full Question is on the Picture I need to continue on this code please ::: #include using namespace std;   struct node { int data; node *next; node(int d,node *n=0) { data=d; next=n;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Data Structute Using c++ Queue 

The Full Question is on the Picture I need to continue on this code please :::

#include <iostream>

using namespace std;

 

struct node
{
int data;
node *next;
node(int d,node *n=0)
{
data=d;
next=n;
}
};

class queue
{
node *front,*rear;
public:
queue();
bool empty();
void append(int el);
bool serve();
bool retrieve(int &el);
//destructor ...
};

 

bool queue::empty()
{
return front==0;
}

queue::queue()
{
front=rear=0;
}

void queue::append(int el)
{
if(front==0)
front=rear=new node(el);
else
rear=rear->next=new node(el);
}

bool queue::serve()
{
if(front==0)
return false;
if(front==rear)
{
delete front;
front=rear=0;
}
else
{
node *t=front;
front=front->next;
delete t;
}
return true;
}

bool queue::retrieve(int &el)
{
if(front==0)
return false;
el=front->data;
return true;
}

 

 


int main ()
{

QueueLinked<int> custQ; // Line (queue) of customers containing the

QueueArray<int> custQ; // Line (queue) of customers containing the
// time that each customer arrived and
// joined the line
int simLength, // Length of simulation (minutes)
minute, // Current minute
timeArrived, // Time dequeued customer arrived
waitTime, // How long dequeued customer waited
totalServed = 0, // Total customers served
totalWait = 0, // Total waiting time
maxWait = 0, // Longest wait
numArrivals = 0; // Number of new arrivals

// Seed the random number generator. Equally instructive to run the
// simulation with the generator seeded and not seeded.
srand(7);

cout << endl << "Enter the length of time to run the simulator : ";
cin >> simLength;

// Put your code here to run this simulation. Use "rand()" to get
// a pseudorandom number that you can use to calculate probabilities.


///starting a minute zero the program will loop through until it has reached the predetermined simLength
minute = 0;
int k;
while(minute != simLength)
{
///check to see if queue is empty
if(!custQ.isEmpty())
{
///if not empty, dequeue customer and record data
timeArrived = custQ.dequeue();
waitTime = minute - timeArrived;
totalWait += waitTime;
totalServed++;
if(waitTime > maxWait)
{
maxWait = waitTime;
}
}
///generate a random number using mod 4 to get appropriate number
k = rand() % 4;
///if the number is one add one person to the queue and increment numArrivals
if(k == 1)
{
custQ.enqueue(minute);
numArrivals++;
}
///if the number is two add two people to the queue and add two to numArrivals
if(k == 2)
{
custQ.enqueue(minute);
custQ.enqueue(minute);
numArrivals += 2;
}

///update the while loop by incrementing the minute variable
minute++;
}


// Print out simulation results
cout << endl;
cout << "Customers served : " << totalServed << endl;
cout << "Average wait : " << setprecision(2)
<< double(totalWait)/totalServed << endl;
cout << "Longest wait : " << maxWait << endl;

 

 

system("pause");
return 0;
}

Time (minutes) Customers Served Average Wait Longest Wait
We can use a queue to simulate the flow of customers through a check-out line in a
store. In this simulation we will have the following details:
minute Queue
isempty?
queue operations
corresponding diagram
ves
no degueue (empty queue)
one check-out line
the expected service time for each customer is one minute (However, they may have
to wait in line before being serviced)
between zero and two customers join the line every minute
1 engueue(0)
1
по
degueue
We can simulate the flow of customers through the line during a time period n minutes long
using the following algorithm:
2 engueue(1)
1
Initialize the queue to empty.
engueue(1)
for ( minute = 0; minute <n; ++minute )
1
{
degueue
1
if the queue is not empty, then remove the customer at the front of the queue.
2 engueue(2)
2
Compute a random number k between 0 and 3.
engueue(2)
1
2
If k is 1, then add one customer to the line.
3
If k is 2, then add two customers to the line.
degueue
Otherwise (if k is 0 or 3), do not add any customers to the line.
1 engueue(3)
2
3
}
4
2
2
3
In addition, the algorithm will keep track of the following:
degueue
2
3
the total number of customers served
O no engueue (k=0)
3
the combined total wait time of all customers
the maximum length of time any of these customers spent waiting in line
Operations on the Queue for the Check-out Line Simulation
Test Plan for "Check-out Line" Simulation Program
Given a time of 5 minutes, the following demonstrates the operations on the queue:
Total Number of
30
60
120
480
-||N||N||
Transcribed Image Text:Time (minutes) Customers Served Average Wait Longest Wait We can use a queue to simulate the flow of customers through a check-out line in a store. In this simulation we will have the following details: minute Queue isempty? queue operations corresponding diagram ves no degueue (empty queue) one check-out line the expected service time for each customer is one minute (However, they may have to wait in line before being serviced) between zero and two customers join the line every minute 1 engueue(0) 1 по degueue We can simulate the flow of customers through the line during a time period n minutes long using the following algorithm: 2 engueue(1) 1 Initialize the queue to empty. engueue(1) for ( minute = 0; minute <n; ++minute ) 1 { degueue 1 if the queue is not empty, then remove the customer at the front of the queue. 2 engueue(2) 2 Compute a random number k between 0 and 3. engueue(2) 1 2 If k is 1, then add one customer to the line. 3 If k is 2, then add two customers to the line. degueue Otherwise (if k is 0 or 3), do not add any customers to the line. 1 engueue(3) 2 3 } 4 2 2 3 In addition, the algorithm will keep track of the following: degueue 2 3 the total number of customers served O no engueue (k=0) 3 the combined total wait time of all customers the maximum length of time any of these customers spent waiting in line Operations on the Queue for the Check-out Line Simulation Test Plan for "Check-out Line" Simulation Program Given a time of 5 minutes, the following demonstrates the operations on the queue: Total Number of 30 60 120 480 -||N||N||
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY