Programming Assignment #2

CS 163: Data Structures

Spring 2009

 

 

 

Problem Statement:

Have you ever spent a long time in the doctor’s office? You see people come in and get helped while you still wait and wait and wait. Obviously, there are different priorities of patients. Those of us with appointments get placed in a queue and pushed onto a stack. Normally, if nothing more pressing comes in while we are there, we get popped off of the stack when it is our turn and handled in the order that we came in.

 

But, when something more pressing happens, maybe an emergency, a new queue of patients that are more critical gets pushed onto the stack.

 

In this way, the queue represents patients that are waiting for their turn, based on the time in which you arrive. The stack handles the ability to add higher priority patients on top of those that have been waiting awhile!

 

Ok, so now for the details of the assignment!

 

Data Structure:

Write a C++ program that implements and uses a queue and a stack. There must be a queue class and a stack class.

The implementation of the application must use a queue and stack abstract data types to perform its operations; do not intermix queue and stack operations in a single data abstraction. In addition, your queue must be implemented using a circular linked list and your stack must be implemented using a linear linked list. 

 

The data that will enqueued/dequeued are the patient’s names and the time of arrival. The data that will be pushed and popped are QUEUE objects (make sure to pass by reference…not by value!).

 

Things you should know...as part of your program:

1) Implement a queue ADT and a stack ADT as two separate classes. Use modular design, separating the .h files from the .cpp files. Remember, .h files should contain the class header and any necessary prototypes. The .cpp files should contain function definitions. Never "include" .cpp files!

2) Use the iostream.h library for all I/O; do not use stdio.h.

3) Make sure to define a constructor and destructor for classes. Your destructor must deallocate all dynamically allocated memory.

4) Each node and each name within the node must be dynamically allocated to be of the appropriate size. Do not use statically allocated arrays in your nodes!

5) Remember to pass by reference whenever possible.

On the due date, turn in:

1.      Make sure to submit a file (e.g., design2.doc) that describes the major design considerations encountered, and all data structures and algorithms used.

 

         This must be written in English using complete sentences. Each major design issue should be described. In the design considerations, discuss what the main design considerations are, why they are the main design considerations, how you solved them, and why you solved the way you did. Think in terms of analyzing your solution!

 

2.       Email your program to your teacher as a zip file

 

IMPORTANT!

Every file must have a comment at the beginning with your first and last name, the class (CS163), the name of the file, and the assignment number. This is essential!