COSC 503: Programming Concepts & Tools

Project 3
Spring 2011

Due: Fri, Mar 25 @ 5 PM
8 points

In lecture, we have started discussing abstract data types, self-referential template classes, and containers. For this project, you'll use a singly-linked list to implement a stack and a queue. Naturally, the classes for these containers must be able to hold any object, so you must implement them as template classes. Specifically, you will implement and use the Node<T> class to implement Stack<T> and Queue<T>.

All of the classes must implement a default constructor, a copy constructor, an overloaded memberwise copy operator (operator=), a size method, an empty method, a clear method, and a destructor. (Not deconstructor! That's POMO. This is C++.) Methods should throw appropriate exceptions, such as bad_alloc, StackEmpty, and QueueEmpty. Use constant parameters and constant methods as appropriate.

It is imperative that you follow our design for the public interface. For Stack<T>, pop must remove and return the object at the top of the stack, push must add an object to the top of the stack, and top must return a reference to the object at the top of the stack. For Queue<T>, dequeue must remove and return the object at the front of the queue, enqueue must add an object to the end of the queue, and front must return a reference to the object at the front of the queue.

Any method that dynamically allocates memory must throw bad_alloc. Any method that returns objects or references to them must throw the appropriate exception when called for an empty container.

To grade your project, we will drop a main function into your directory and compile and run. Our main function will test all aspects of all of your two classes. As a consequence, it is imperative that you test all of your methods thoroughly, preferably as you're developing them.

Instructions for Electronic Submission:

At the top of the file main.cc (or the file containing the main function), place the following header comment, with the appropriate substitutions:

/*
 * COSC 072 Project 3
 * Name: <your name>
 * ID: <GoCard ID>
 * E-mail: <e-mail address>
 * Instructor: Maloof
 *
 * In accordance with the class policies and Georgetown's Honor Code,
 * I certify that, with the exceptions of the class resources and those
 * items noted below, I have neither given nor received any assistance
 * on this project.
 */

You'll be submitting p3 exactly like you submitted p2. The code for this assignment is p3, and you can submit using the command:

seva% java -jar submit.jar -a p3 -f p3.zip
If you need to include a message about your submission, then place the message in a file named README. Place the README file in the project's directory.