SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Pointers And Linked Lists
Exercise:
Programming Projects
Question:8 | ISBN:9780321531346 | Edition: 7

Question

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

Video Note

Solution to

Programming

Project 13.6

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 <ctime>

...

int main()

{

long seconds;

seconds = static_cast<long>(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.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.