Homework 6: Bob's Wacky Fun World
Short Description:
Write a program that simulates customers waiting in line at a novelty store.
This assignment is worth 100 points.
Goals
When you finish this homework, you should:
- have implemented a list, stack and queue.
- have gained experience working with pointers and dynamic memory.
- Improved your ability to use classes.
Formal Description
Bob's Wacky Fun World is a novelty shop. To make the experience more fun, Bob
has implemented a number of "amusing" features. For example, the "exploding"
toilet paper is a real hit.
Bob is considering adding a rotating line. The front of the checkout area
will be replaced with a giant rotating disk (much like a merry-go-round), which turns at a rate of 1 turn per hour. At the beginning of the hour, the entrance is just past the 3 o'clock position, and the exit is just past the 9 o'clock position. As time passes, line rotates in a clockwise direction, until just before 1/2 past the hour, the exit is almost to the 3 o'clock position and the entrance is just about to the 9 o'clock position. After 1/2 past the hour, the entrance becomes the exit and the exit becomes the entrance. In other words, the
line is reversed. (See the figures below).
Since Bob has had some problems with some of his ideas in the past, he would like you to help him out by simulating what would happen with this configuration.
You should build the following classes:
- Customer class:
- Data:
- Customer ID (int)
- Time added to line (int)
- Number of Items (int)
- Methods:
- Create customer(int id, int items, int time in line).
- int Items()
- int TimeAddedInLine()
- int Id()
- You may add any additional methods you need.
- Casheer class:
- Data:
- Methods:
- bool IsFree(): False if the cashier is processing a customer
- void AddCustomer(customer class) : adds a customer to the class.
- void DoTick(): Allows one time period to pass.
- You may add any additional methods you need.
- Queue class:
- Data:
- Customer class data
- This must be a pointer based implementation.
- Methods:
- Constructor, destructor.
- Enqueue(item) : add item to the end of the queue
- item Dequeue(): return the first item from the queue, and delete it. This is not defined for an empty queue.
- bool IsEmpty()
- item Front(): return the first item from the queue. This is not defined for an empty queue.
- You may not implement any other methods on this class.
- Stack class:
- Data:
- Customer class data
- This must be a pointer based implementation.
- Methods:
- constructor, destructor.
- bool IsEmpty()
- Push(item): Place an item on the stack;
- item Pop(): Remove the top item from the stack and return it. This is not defined on an empty stack.
- item Top(): Return the top item on the stack, but do not remove it. This is not defined on an empty stack.
- You may not implement any other methods on this class.
You should have the following constants in your program:
- Pa the probability that a customer arrives in a given time period. (Value .3)
while rand() < P_SUB_A
add a new customer to the queue
- Pi the probability that the customer purchases another item. (value .5)
customerItems = 1
while rand() < P_SUB_I
customerItems ++
- Ti The time to process an item. (scanning, bagging, ...) (value 3)
- Tb The base time to process a customer (greeting, chatting, ...) (value 1)
TimeToPocess = T_SUB_B+ T_SUB_I * customer.Items()
Output
Each time an event occurs, you should output what happens:
Time O
The store opens.
...
Time 88
Customer 431 entered the line with 2 items
The cashier finished processing customer 429
Customer 429 departs with 20 ticks in line and 1 line rotations,
Time 89
Customer 432 entered the line with 3 items
Customer 430 reached the cashier.
The cashier will take 6 ticks to process customer 430
Time 90
The Wheel Spins
...
Time 600:
The store closes.
...
Time 643
The cashier finished processing customer 782
Customer 782 departs with 13 ticks in line and 0 line rotations
Discussion
When the wheel spins, you should call a routine which will reverse the order of the queue. This is best done by using the stack. You should keep track of the number of times a customer is
The main loop of your program should look something like this:
OpenStore()
for time=0 to 600 do
if (time % 30 == 0)
ReverseQueue(Q)
while NewCustomers()
Q.Enqueue(MakeNewCustomer(time))
if cashier.IsFree() && !Q.IsEmpty() {
cashier.AddCustomer(Q.Dequeue())
}
cashier.DoTick()
while !Q.IsEmpty()
time ++
if cashier.IsFree() && !Q.IsEmpty() {
cashier.AddCustomer(Q.Dequeue())
}
cashier.DoTick()
CloseStore(time)
Submission
This homework is due by class time December 12.