Homework 5
Two Implementations of Queues

Due: Tuesday, December 4, 2012 at 5pm

Abstract

Write two different queue implementations for the same interface. Show that both implementations work in a simulation of a queue of customers in, for example, a supermarket or bank.

Outcomes

After successfully completing this assignment, you will be able to...

Before Starting

Read Chapter 12 in Deitel & Deitel, particularly sections 12.1 - 12.4 and 12.6 Also read section 14.4, "Using Command-Line Arguments".

The Assignment

In this assignment you will create two versions of a program that simulates a queue of customers being served by a teller in a bank. Both versions of the program will store the information about each customer in a queue. The two versions differ in that in one version, the queue will be implemented using a linked list, and in the other version, the queue will be implemented using an array.

Your programs should comprise multiple files, and you will build them by running make (the makefile will be provided). Download and unzip the zip file at the following URL:

http://www.cs.wpi.edu/~cs2301/b12/hw5-files.zip

Your directory should now contain the files Simulation.h, Simulation.c, Statistics.h, Statistics.c, Queue.h, Queue-array.c, Queue-list.c, main.c, and makefile. (Note that you will be making changes only to the files Queue-array.c and Queue-list.c.)

These files contain the code that simulates the arrival of customers in the queue. Customers arrive at random intervals. If the bank teller is free, service begins immediately. Otherwise, the customer waits in the queue. The time it takes to serve a customer is also random. When the teller finishes with one customer, he/she begins serving the next customer in the queue, if any, or waits patiently for a new arrival. The simulation runs for a specified amount of time. At the end of that time, no new arrivals are accepted, but all waiting customers are served.

The simulation outputs the average time from when a customer arrives to when service is completed, along with the standard deviation, the maximum waiting time of any customer, and the maximum number of customers in the queue.

The simulation can be run with the following command:

./PA5 simTime meanArrivalInterval meanServiceTime seed verbose
where PA5 is the name of the executable file created by make (you will be choosing to run either PA5-array or PA5-list; see "Using the makefile", below). The first three arguments may be integers or floats. The seed (for the random number generator) must be an integer. If the word "verbose" is included, the simulation prints out a lot of detail. Any of the operands may be defaulted, and if so, all subsequent operands are also defaulted. The default values are 720 minutes of simulation time, an average of 2.0 minutes between arrivals, an average service time of 2.0 minutes, a random number seed of 1, and non-verbose operation.

Study the given code carefully. There may be one or more questions about it on Exam 3.

You will notice that the simulation is fully implemented except for one part - the queue model. The interface Queue.h contains the functions needed by the simulation, but the files Queue-array.c and Queue-list.c contain only stubs for these functions. If you were to build and run this simulation, it would stop at the first queue operation with an error message.

This is the essence of this assignment. You need to implement the queue functions not once, but twice, using two different approaches. These approaches are:

The existing simulation does not do any error checking to see if the queue is full. This will be a problem if the fixed size queue is not large enough to accomodate the maximum size needed by the program. It can also be a problem if you allow the linked list queue to grow to an unbounded size. You must add error checking and take appropriate action in the case that the queue is full.

Using the makefile

The makefile provided with this assignment generates two executable files: PA5-array and PA5-list. The two versions differ only in which version of the queue they use. PA5-array is built using Queue-array.c, and PA5-list is built using Queue-list.c. You can use the makefile to generate both executables by typing make all, or you can specify one of the targets individually by typing, for example, make PA5-list.

Deliverables

Here is what you should submit for the assignment: Submit your files using web-based turnin.

Grading

This assignment is worth 50 points: Programs must build successfully using the given makefile, and using all of the other given .h and .c files, as written, in order to receive any credit for functionality.. Do not make changes to any of the files provided, except for Queue-array.c and Queue-list.c.

Programs submitted after 5pm on December 4 will be tagged as late, and will be subject to the late homework policy.