Question: IN C++ (Must Use a Queue) Simulate a big-box retail store, where customers shop and choose the merchandise they want to buy. Each customer then
IN C++ (Must Use a Queue)
Simulate a big-box retail store, where customers shop and choose the merchandise they want to buy. Each customer then proceeds to get into a line to wait to be checked out. When there is an available cashier, the customer goes to the register where that cashier is waiting. When the cashier is finished checking the customer out, the customer exits the register and is considered finished.
What we're interested in doing is tracking these movements: when customers enter lines, exit lines and enter registers, and finally exit registers. We'll then report various statistics at the conclusion of the simulation, to summarize the overall outcome.
Arrangements of lines and registers
There are two different arrangements of lines and registers that our simulation will support.
- One or more registers, each with its own separate line. A customer in a particular line will only ever proceed to the corresponding register.
- One or more registers, with one shared line feeding customers to all of them.
Example input:
The italiczed portions are included here for descriptive purposes, but are not included in the actual input.
4 the length of the simulation, in minutes 3 the number of registers 3 the maximum line length, beyond which customers be lost M S for a single line, M for multiple lines (one for each register) 40 register #1 takes 40 seconds to process a customer 50 register #2 takes 50 seconds to process a customer 30 register #3 takes 30 seconds to process a customer
There are a few notes to be aware of:
- When we talk about the length of the simulation, we don't actually intend for the simulation to take that long to run. The goal is for the simulation to give a quick answer to the question of "What would a day in my store look like if we arranged things like this?"
- We'll say that each register has a register number and that they are numbered consecutively starting from 1. Similarly, lines will have a line number and they're also numbered consecutively starting from 1.
- The simulation length is given in minutes, while the processing times for each register are given in seconds.
Each line in the customer arrival section of the input consists of two numbers: a positive number of customers and the time that these customers arrival. (Time in our simulation is always measured in terms of the number of seconds since the simulation started.) You can assume that the time associated with each line describing an arriving of customers will be greater than the time associated with the previous one.
The input will always end with a line consisting of the word END. That doesn't mean that the simulation should end immediately; it just means that there are no more customer arrivals.
- In any given second of simulation time, customer arrivals are always considered before customers are moved into and out of registers.
- When n customers arrive at a particular time, we assume that they're separate they each have a shopping basket and are interested in engaging in a separate transaction. Each of them has a decision to make and they make them one right after the other:
- The customer chooses the shortest line and enters it. Note that this is based only on how many customers are in each line; the presence or absence of a customer at any registers is not considered. When there is a tie (i.e., two lines are equally the shortest), the customer will always choose the line with the smallest line number (e.g., if lines 3 and 7 are equally the shortest, the customer will enter line 3).
- If all of the lines are the maximum length specified in the setup section, the customer is not willing to wait, and instead leaves the simulation immediately. That customer is considered to be lost. (This is a crude representation of a store being busy enough that it drives away customers.)
- Whenever a register is unoccupied, a customer immediately moves from the corresponding line and into the register. That customer will stay for the appropriate number of seconds (as determined by the processing time for that register, specified in the setup section). At that time, the customer will leave the register and will immediately be replaced by another.
- For the sake of simplicity, we'll assume that customers will never move from one line to another once they've entered a line, nor will a customer ever enter a register from any line other than the one that corresponds to it.
The output
The output of your simulator consists of two sections:
- The log, which indicates each time an "interesting" event occurs. The log begins with the word LOG alone on a line, followed by one line of output for each event. Each line of output describing an event consists of an integer simulation time (the number of seconds since the simulation started), a space, and then a description of the event. The following kinds of events are required to be logged:
- The simulation started
- The simulation ended
- A customer entered a line, in which case we want to know which line number and how long the line is now (including the new customer)
- A customer exited a line, in which case we want to know which line number and how many seconds the customer waited in that line
- A customer entered a register, in which case we want to know which register number
- A customer exited a register, in which case we want to know which register number there's no need to see how long they waited, as this is always the same for a given register
- A customer has been lost (i.e., they left without waiting in line because all lines were maximum length)
- The "stats" section. This section begins with a blank line (to separate it from the log visually), followed by the word STATS alone on a line, followed by these statistics:
- How many customers entered a line during the simulation
- How many customers exited a line during the simulation
- How many customers exited a register during the simulation we don't show many customers entered a register, because every customer who exits a line immediately enters a register
- The average wait time, in simulation seconds, for customers who exited a line. We only care about how long they waited in line, and we only measure this for customers who exited a line; customers still remaining in line at the end of the simulation are not included. Display this value to two digits after the decimal point.
- How many customers are still left in line at the end of the simulation (i.e., they've entered a line but not exited it yet)
- How many customers are still left at a register at the end of the simulation (i.e., they've entered a register but not exited it yet)
- How many customers were lost during the simulation
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
