CSC 222: Computer Programming II
Spring 2004

HW5: Queues and Simulation

For this assignment, you are to complete the bank simulation project, which uses a queue to simulate customers arriving and being served in a small bank. Recall the following assumptions:

The following files have been provided for you: Customer.h, Customer.cpp, Teller.h, Teller.cpp, Die.h, Die.cpp, ServiceCenter.hand banksim.cpp.

Part 1: Implementing ServiceCenter

To complete the simulation, you are to implement the ServiceCenter class. An object of this class contains a single Teller object for serving customers, and a queue of customers waiting to be served. The addCustomer member function should create a new customer, add them to the waiting queue, and display information about the customer. The serveCustomers member function should perform a step in the simulation, checking to see if the teller has finished with a customer and, if so, whether a new customer can be served. It should also display a message if the teller finishes or begins serving a customer.

For example, the output of the simulation should look like the following:

What is the time duration (in minutes) to be simulated? 10 What percentage of the time (0-100) does a customer arrive? 30 2: Adding customer 1 (job length = 4) 2: Serving customer 1 (finish at 6) 4: Adding customer 2 (job length = 3) 5: Adding customer 3 (job length = 1) 6: Finished customer 1 6: Serving customer 2 (finish at 9) 9: Adding customer 4 (job length = 3) 9: Finished customer 2 9: Serving customer 3 (finish at 10) 10: Finished customer 3 10: Serving customer 4 (finish at 13) 13: Finished customer 4

Part 2: Maintaining Statistics

Once you have the simulation working correctly, add a member function named DisplayStats that displays statistics on the simulation. You should modify the ServiceCenter class so that an object keeps track of:

  1. the number of customers whose jobs have been completed,
  2. the average waiting time for all customers whose jobs have been completed, and
  3. the longest waiting time for any customer.

The DisplayStats member function, when called, should display these statistics in a readable form. Add a call to the banksim.cpp program so that DisplayStats is called at the end of the simulation to display statistics.

Part 3: Analysis

Once you have your bank simulation program working, answer these questions:
  1. Assuming a banking day of 8 hours (240 minutes), how many customers would you expect to serve if the arrival probability were 20%. Do your simulations support this answer?
  2. Assuming a banking day of 8 hours and an arrival probability of 15%, what is the average wait time for customers at the bank. Run several simulations and comment on the consistency of the results.
  3. Assuming a banking day of 8 hours, what arrival probability can the bank handle and still keep the maximum wait time for customers under 10 minutes. Explain how you came up with this number.