COSC 072: Computer Science II

Project 3
Summer 2010

Due: Thu, Aug 5 @ 10 PM
12 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 and StackEmpty or 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 on 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 on the top of the stack. For Queue<T>, dequeue must remove and return the object from 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 or removes objects must throw the appropriate exception when called for an empty container (i.e., StackEmpty or QueueEmpty).

To grade your project, we will drop a main function into your directory and compile. main will test all aspects of all of your 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 the other assignments. 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. Just zip it up and submit it via Blackboard.

Copyright © 2019 Mark Maloof. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed.