Problem

Modify or rewrite the Queue class (Display 13.21 through 13.23) to simulate customer arriv...

Modify or rewrite the Queue class (Display 13.21 through 13.23) to simulate customer arrivals at the Department of Motor Vehicles (DMV) counter. As customers arrive, they are given a ticket number starting at 1 and incrementing with each new customer. When a customer service agent is free, the customer with the next ticket number is called. This system results in a FIFO queue of customers ordered by ticket number. Write a program that implements the queue and simulates customers entering and leaving the queue. Input into the queue should be the ticket number and a timestamp when the ticket was entered into the queue. A ticket and its corresponding timestamp is removed when a customer service agent handles the next customer. Your program should save the length of time the last three customers spent waiting in the queue. Every time a ticket is removed from the queue, update these times and output the average of the last three customers as an estimate of how long it will take until the next customer is handled. If nobody is in the queue, output that the line is empty.

Code to compute a timestamp based on the computer’s clock is given below. The time (NULL) function returns the number of seconds since January 1, 1970, on most implementations of C++:

#include

int main()

{

long seconds;

seconds = static_cast<7ong>(time(NULL));

cout « “Seconds since 1/1/1970: “ « seconds « endl;

return 0;

}

Sample execution is shown here:

The line is empty.

Enter ‘1’ to simulate a customer’s arrival, ‘2’ to help the

next customer, or ‘3’ to quit.

1

Customer 1 entered the queue at time 100000044.

Enter ‘1’ to simulate a customer’s arrival, ‘2’ to help the

next customer, or ‘3’ to quit.

1

Customer 2 entered the queue at time 100000049.

Enter ‘1’ to simulate a customer’s arrival, ‘2’ to help the

next customer, or ‘3’ to quit.

1

Customer 3 entered the queue at time 100000055.

Enter ‘1’ to simulate a customer’s arrival, ‘2’ to help the

next customer, or ‘3’ to quit.

2

Customer 1 is being helped at time 100000069. Wait time = 25 seconds.

The estimated wait time for customer 2 is 25 seconds.

Enter ‘1’ to simulate a customer’s arrival, ‘2’ to help the

next customer, or ‘3’ to quit.

2

Customer 2 is being helped at time 100000076. Wait time = 27

seconds.

The estimated wait time for customer 3 is 26 seconds.

Enter ‘1’ to simulate a customer’s arrival, ‘2’ to help the

next customer, or ‘3’ to quit.

1

Customer 4 entered the queue at time 100000080.

Enter ‘1’ to simulate a customer’s arrival, ‘2’ to help the

next customer, or ‘3’ to quit.

2

Customer 3 is being helped at time 100000099. Wait time = 44 seconds.

The estimated wait time for customer 4 is 32 seconds.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 13
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT