Skip to content

CS 1415 - Lab #15

Objective:

Program a Simulation using the STL queue

Preparation:

Review Chapter 18 from Starting Out with C++ by Gaddis.

Programming:
  1. You will use the STL queue container adapter. All your code should be in one file. Name the file LlllFfffLab15.cpp where Llll is the first four letters of your last name and Ffff is the first four letters of your last name.
  2. Write a program that simulates a line at a bank. The line is represented with a queue object. Customers arrive at the bank and get in line at random integer intervals of 1-4 minutes. Each customer is served in random integer intervals of 1-4 minutes. The program should allow the user to input how many minutes to simulate (480 for an 8-hour day). The program should use the following algorithm:
    1. Get a random integer between 1 and 4 to represent the minute at which the first customer arrives. The Simulation begins with this time by:
      1. Indicating that the first customer arrived.
      2. Determining the first customer's leave time by adding a service time (random integer from 1 to 4) to their arrival time.
      3. Determine the arrival time of the next customer (random integer 1 to 4 added to the first customer's arrival time).
    2. For each remaining minute of the work day:
      1. If it is time for the current customer being serviced to leave:
        1. Indicate that.
      2. If it is time for the next customer to arrive:
        1. Indicate that.
        2. Enqueue this next customer.
        3. Determine the arrival time of the customer after that one.
      3. If there is no current customer being serviced (they have left):
        1. If there is a customer in the queue:
          1. Dequeue next customer to be serviced.
          2. Determine that customer's service completion time (random integer from 1 to 4 added to the current time).
    3. For each minute after closing that there are still customers being serviced:
      1. If it is time for the current customer being serviced to leave:
        1. Indicate that.
      2. If there is no current customer being serviced:
        1. If there is a customer in the queu:
          1. Dequeue next customer to be serviced.
          2. Determine that customer's service completion time (random integer from 1 to 4 added to the current time).
  3. Your program should output answers to these two questions:
    1. What is the maximum number of customers ever in the queue?
    2. What is the longest wait any one customer experiences?
      • Wait time is defined as time standing in line waiting to be serviced. It does not include time being serviced. 
  4. Verify your program works correctly.
  5. Submit your source code file to garth.sorenson@snow.edu. Due at 8:00 am on 21 April.