CS 162 Spring 2000 Assignment 9 – Stacks (vs Queues)
100 pointsAssigned: 04/17/2000
Due: 04/28/2000 at the start of class – but note that another assignment will be started in the next lab – try to finish in lab.
Pairs: You may work in pairs if you want. Note, during the course of the semester, you cannot pair with any one person more than twice. If you work in a pair, turn in ONE copy that is the work of both of you, with both of your names on it. Each member of the pair will receive the same grade for that lab.
Main Assignment:
"So the last shall be first, and the first last". (Matthew 20:16)
New Bank of Philadelphia has decided to take this statement to heart, and has set up their teller lines as a stack rather than a queue. That is, customers when they enter the branch move directly to the front of the line. Your job is to simulate activity at the bank, much as Budd’s program simulates a bank that uses a queue. (on my Review page on the WWW I have posted an improved version of Budd’s program). Assumptions that you should make: 1) each minute there is a 90% chance that a new customer will enter the branch; 2) there are 4 tellers, each of which can service one customer at a time; 3) everything happens once a minute; 4) customers take a period of time with the teller randomly varying between 2 and 7 minutes (as in Budd’s example); 5) the simulation should run for 60 minutes (as in Budd’s example).
You may use the available teller and customer classes, and focus on writing the main function. The main should show the activity – customers arriving, customers getting served, as in the posted example. After the end of the simulation, the program should display the mean (average) waiting time, the mean (average) line length, and the maximum wait (as shown in the example below – the example only simulates 10 minutes to save paper and photocopying costs).
ADDITIONAL TASK: Run the queue version. Write out (use Word or something so I can easily read) what you observe as differences between how the stack and queue versions perform in their task. What is the major problem with New Bank’s approach? Are there any positives?
Details
:1)
You MUST use the stack library.Hand-in:
1)
Listing of the programMiscellaneous:
1
) If you have any questions about what should be done, please ask!!2) MAKE SURE YOUR PROGRAM WORKS! (i.e. more than just removing compile errors).
3) Remember: Indentation, meaningful variable names, symbolic constants, and meaningful comments. Weaknesses in any of these could result in points off. Also make sure you put YOUR NAME(s), section, and e-mail address in comments at the beginning of the program.
Sample Interaction:
Customer arrives at time: 0
Customer who arrived at 0 served by teller 0 after a wait of 0 mins
* time: 0 line length: 0|
num customers: 1 total wait so far: 0
Wait> c
Customer arrives at time: 1
Customer who arrived at 1 served by teller 1 after a wait of 0 mins
* time: 1 line length: 0|
* time: 2 line length: 0|
Customer arrives at time: 3
Customer who arrived at 3 served by teller 2 after a wait of 0 mins
* time: 3 line length: 0|
Customer arrives at time: 4
Customer who arrived at 4 served by teller 3 after a wait of 0 mins
* time: 4 line length: 0|
Customer arrives at time: 5
Customer who arrived at 5 served by teller 2 after a wait of 0 mins
* time: 5 line length: 0|
num customers: 5 total wait so far: 0
Wait>
Customer arrives at time: 6
* time: 6 line length: 1| 6|
Customer arrives at time: 7
Customer who arrived at 7 served by teller 0 after a wait of 0 mins
Customer who arrived at 6 served by teller 1 after a wait of 1 mins
* time: 7 line length: 0|
Customer arrives at time: 8
* time: 8 line length: 1| 8|
Customer arrives at time: 9
* time: 9 line length: 2| 9| 8|
average wait:0.142857
Average line length: 0.4
max wait:1