CS 162 Spring 2000 Assignment 9 – Stacks (vs Queues) 100 points

Assigned: 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.

  1. You can take major inspiration from the queue version, in fact you can copy and modify it if you want.
  2. The posted program includes all code in one file – how Budd posted it on his WWW site. I strongly recommend that you put separate classes in separate files (e.g. teller.h and teller.cpp, customer.h and customer.cpp).
  3. Stop every so often so that we can see what is happening without it all streaming past wildly on the screen. I stopped, waiting for a char, every 5 simulated minutes.
  4. Any customers still in line at the end of the simulation are not included in the average wait, since it is completely unknown how long they would wait.

Hand-in:

1) Listing of the program

  1. Disk with all relevant .h and .cpp files, plus your .exe file. NAME YOUR CLIENT FILE yourlastname9.cpp Name your project yourlastname9 so that the executable will be yourlastname9.exe. If you are working in pairs, use both last names (e.g. redmondsmith9.cpp)
  2. Your answer to the question above – typed.

Miscellaneous:

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> c

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