COSC-052: Computer Science II

Project 3
Spring 2017

Due: F 3/24 @ 5 PM
8 points

In lecture, we have started discussing self-referential classes, template classes, container classes, and abstract data types. For this project, you'll use a singly-linked list to implement a stack and a doubly-linked list to implement a double-ended queue or deque (pronounced "deck"). 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 you will implement and use the DLNode<T> class to implement Deque<T>. I put some starter code on cs-class, which you can copy to your directory by typing the command:

cp ~maloofm/cosc052/p3.zip ./

The container classes must implement a default constructor, a copy constructor, an overloaded memberwise assignment operator (operator=), a size method, an empty method, a clear method, and a destructor. (Not deconstructor! That's POMO. This is C++.)

It is imperative that you follow the design for the public interface. Stack<T>::pop must remove and return the object from the top of the stack, Stack<T>::push must add an object to the top of the stack, and Stack<T>::top must return a reference to the object on the top of the stack. Deque<T>::removeFront and removeBack must remove and return the object from the front and back of the deque, respectively, insertFront and insertBack must add an object to the front and back of the deque, respectively, and Deque<T>::front and back must return a reference to the object at the front and back of the deque, respectively. Finally, I would recommend implementing the method printInternal for both classes so you can inspect the internal state of the containers and their linked lists during development.

Any method that dynamically allocates memory must throw bad_alloc. Any method that returns or removes objects must throw the NoSuchObject exception when called for an empty container. Derive NoSuchObject from logic_error.

Instructions for Electronic Submission

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

/*
 * COSC-052 Project 3
 * Name:
 * ID:
 * Instructor:
 *
 * 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.

Plan B

If Autolab is down, upload your zip file to Blackboard.

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