Program Four
Write a program that simulates the checkout line at a simple shop.
This shop has a single cash register and a single cashier.
Customers arrive in the line at random intervals, with a random number
of items. They are checked out in the order that they arrive.
Begin by writing a queue class. This class should implement
- void Enqueue (Item_Type)
- void Dequeue ()
- Item_Type Front()
- bool IsEmptyQ()
- A constructor
- void PrintQ()
Your implementation should be based on dynamic memory and pointers.
You should write a driver that tests your queue class.
Next write the simulation.
We will write this simulation based on a time unit called a tick.
- The cashier takes 30 ticks to bag the items, make change and
other basic tasks for every customer.
- The cashier takes an additional 3 ticks per item to scan the price.
- Make sure that these are constants and can be changed to
change the nature of the simulation.
A customer can be described as follows:
- Each customer has at least 2 items, and can have as many as 20.
- Generate a random number of items in this range for the customer
when they arrive.
- A time that they arrive in the queue.
- Again, make sure to use constants where applicable.
Customers arrive in line every 100 ticks based on the following table:
Number arriving in line | Chance |
0 | 15 |
1 | 48 |
2 | 32 |
3 | 5 |
The simulation should operate as following:
- The clock starts with 0 ticks.
- The cashier has a clock that starts at 0 ticks as well.
- At 0 ticks check for new customers, add them to
the queue if they arrive.
- Every 100 ticks, starting with 0, check for new customers and add them
to the queue if they arrive. (You will add customers twice for tick 0)
- If the cashier is not busy, remove a customer from the queue, and
calculate the time spent on that customer. Advance the cashier's clock
by that amount of time.
- Repeat the previous step until
- The queue is empty
- The cashiers clock exceeds the clock + 100
- Repeat this for 20 cycles (2,000 ticks)
At each 100 ticks, you should print out the entire queue.
Each time the cashier services a customer, you should print out
a message indicating this fact, the current time and they time that they
will finish. You should also print out the customer information for the
customer that is being checked out.
Please make sure that you use good programming practices, that your
program is well documented, and takes advantage of modular compilation.
Please make sure that your code is well structured and easy to read.
When you are finished, please create a web page containing links to your
files as well as a tar file of the entire project. Make a README file
that describes the project and any items of interest. Send an email
message with the URL to this page to your instructor.