For this program, you will model the flow of customers through a grocery store check- out queue.
To create this simulation, you must model both the passage of time and the flow of customers through the checkout process. You can model time using a loop in which each iteration corresponds to a set time interval - one (1) minute, for example. You can model the flow of customers using a queue in which each data item corresponds to a customer in the line.
To complete the simulation, you need to know the rate at which customers join the line, as well as the rate at which they are served and leave the line. Suppose the grocery store check-out has the following properties:
You can simulate the flow of customers through the checkout during a specific time period t minutes long using the following algorithm (this basic algorithm works with many simulation scenarios):
1. Initialize the queue to empty.
2. While the simulation is not done:
3. Check out the all customers remaining in queue.
4. Display summary information showing total customers served, average wait time, longest wait time, and the number of customers remaining in queue at the end of the simulation. To maintain good customer relations, any customers in queue will be served, extending the simulation time to accommodate them.
Extend the std::list< T > class to implement a template Queue class with the following interface:
/// A container adapter that gives the programmer the functionality of a
/// queue -- specifically, a FIFO (first-in, first-out) data structure.
/// The class template acts as a wrapper to the underlying container --
/// only a specific set of functions is provided. The Queue pushes the
/// elements on the back of the underlying container and pops them from
/// the front.
template < class T >
class Queue : protected std::list< T > {
public:
/// Returns reference to the first element in the Queue. This element
/// will be the first element to be removed on a call to pop().
T& front();
/// Returns reference to the last element in the Queue. This is the most
/// recently pushed element.
T& back();
/// Checks if the underlying container has no elements.
bool empty() const;
/// Pushes the given element 'value' to the end of the Queue.
void push(const T& value);
/// Removes an element from the front of the queue.
void pop();
};
Use your derived Queue class to facilitate your simulation.
Read the number of minutes to run the simulation from the command line. (The command line argument must be converted from a c-string to an integer value.) If no command line argument is provided, default to 1440 minutes (24 hours). If a command line argument is provided, then check its integer value. If less than 30, display a usage message and terminate. Else, run the simulation for the number of minutes passed via the command line.
Create a program to model the grocery store checkout described above. Your program should update the following information during each simulated minute.
The data that are stored in the queue should contain everything that is necessary to 1) represent the customer and 2) compute the previous statistics. To compute how long a customer waited to be served, you need the difference in time from when the customer arrived to when the customer completed checkout. There is no additional information needed in the statistics, nor is there any customer-specific information (e.g., items purchased) that is used for our simple simulation. Therefore, we can represent the customer in the queue simply by using the simulated time the customer entered the queue.
Use your program to simulate the flow of customers through the checkout process and complete the table shown in the Sample Output below. Note that the average wait is the combined waiting time divided by the total number of customers served.
Input is read from the command line and converted to an integer value. If no command line argument is provided, the simulation duration is set to 1440 minutes (24 hours). If the command line argument's value is less than 30 minutes, print the error message shown and exit. (Note: the name of the program should be taken from the command line argument and not hard-coded into your program. A user may choose to rename the program.)
Simulated data is shown. Your results will differ. Average time should be displayed with one decimal digit of precision.
$ ./pa18b 30
Simulation duration: 30 minutes
Customers Served: 23
Average Wait: 2.5 minutes
Longest Wait: 6 minutes
Customers in queue: 0
$ ./pa18b hello!
Invalid duration.
Usage: ./pa18b minutes (min 30)
$ ./pa18b 10
Invalid duration.
Usage: ./pa18b minutes (min 30)
$ ./pa18b
Simulation duration: 1443 minutes
Customers Served: 907
Average Wait: 6.1 minutes
Longest Wait: 11 minutes
Customers in queue: 3