Question
C++ program based on this algorithm. The Algorithm We can use a queue to simulate the flow of customers through a check-out line in a
C++ program based on this algorithm.
The Algorithm
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:
1.one check-out line
2.the expected service time for each customer is one minute (However, they may have to wait in line before being serviced)
3.between zero and two customers join the line every minute
We can simulate the flow of customers through the line during a time period n minutes long using the following algorithm:
Initialize the queue to empty. for ( minute = 0 ; minute k between 0 and 3. If k is 1, then add one customer to the line. If k is 2, then add two customers to the line. Otherwise (if k is 0 or 3), do not add any customers to the line. }
In addition, the algorithm will keep track of the following:
1.the total number of customers served
2.the combined total wait time of all customers
3.the maximum length of time any of these customers spent waiting in line
reference :
http://www.cs.uregina.ca/Links/class-info/210/Queue/
Given a time of 5 minutes, the following demonstrates the operations on the queue: queuequeue operations sempty? corresponding diagram 0yes no dequeue (empty queue) 1enqueue(o) 0 no 2 enqueue(1) enqueue(1) no 2 |enqueue(2) enqueue(2) 2 no 2 2 1 enqueue(3) no dequeue 0 no enqueue (k-o) Notice that the data in the node is the time (minute) that the "customer" joined the line. This data is used to compute the wait time of a customer. Given a time of 5 minutes, the following demonstrates the operations on the queue: queuequeue operations sempty? corresponding diagram 0yes no dequeue (empty queue) 1enqueue(o) 0 no 2 enqueue(1) enqueue(1) no 2 |enqueue(2) enqueue(2) 2 no 2 2 1 enqueue(3) no dequeue 0 no enqueue (k-o) Notice that the data in the node is the time (minute) that the "customer" joined the line. This data is used to compute the wait time of a customerStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started