COSC 072: Computer Science II

Project 2
Spring 2005

Due: Feb 25 @ 5 PM
6 points

In lecture, we are developing the Stack<T> class and the Queue<T> class. Since we're implementing both using the Node<T> class, the implementation of some operations will be identical for both classes.

The empty method is a good example. For both classes, the empty method returns true if the external pointer (e.g., contents) is null; it returns false otherwise. This suggests that, instead of implementing such methods twice, once in Stack<T> and once in Queue<T>, perhaps we should implement a base class consisting of these common elements and derive Stack<T> and Queue<T>. And by golly, that's what we're going to do for this project.

The first task is to identify elements common to both classes: common data members and common methods. Use this information to implement the Container<T> class.

Next, implement the Stack<T> class and the Queue<T> class by deriving them from the Container<T> class. The methods for adding and removing elements and their names must be appropriate for the container. For example, for adding elements, programmers must have available Stack<T>::push and Queue<T>::enqueue. There should not be a general method for adding, such as Stack<T>::addFront and Queue<T>::addFront. Moreover, methods of one container cannot be accessible from the other. For example, the methods Stack<T>::enqueue and Queue<T>::push should not exist. Methods of both classes should throw appropriate exceptions.

You must design a testing scheme that thoroughly tests both classes, but with a minimal number of tests. Your main function should implement this testing scheme. The main function should print the results of these tests to standard output (cout), and the results should be in a format that the TAs and I can quickly and easily understand. The main function should also catch all potentially thrown exceptions, and you should test the ones possible. A component of your grade will be how well you satisfy all of these constraints. It is fine if you use int or char to instantiate the containers.

All class definitions and class methods must be documented with Doc comments. Doc comments for class definitions must include @author and @version tags. Doc comments for methods must include @param, @return, and @throws tags, where appropriate.

I'm sure at some point while doing P1 and wrestling with the Makefile you thought, "There's gotta be a better way to do this." And indeed, there is. I've written a more flexible Makefile, which you should be able to use for the rest of the semester (and perhaps for the rest of your life) with little modification. I've placed it in a gzipped tar file in my top-level directory on gusun. To retrieve it, type

% cp ~maloofm/p2.tar.gz ./
To decompress the archive, type
% gunzip p2.tar.gz
To extract the archive's contents, type
% tar -xf p2.tar
This will create a directory named p2, and a Makefile and two other files will be therein. You can put all of the files for your project in this directory.

To descend into the directory, type

% cd p2
If you're using Dev with .cpp files, then take a look at Makefile.cpp. If you're using g++ with .cc files, then you can remove Makefile.cpp. Don't worry about Makefile.dep. Instructions are in comments at the top of each Makefile. We will discuss in class how this Makefile works.

If you need to include a message to your TA about your submission, then place the message in a file named README. Place the README file in the p2 directory.

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 modifications:

//
// COSC 072 Project 2
// Name: <your name>
// ID: <GoCard ID>
// E-mail: <e-mail address>
// Instructor: Maloof
// TA: <TA's name>
//
// 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.
//

Although you may use any C++ compiler to develop your program, it must run under UNIX and must compile using GNU g++. You must also provide a working UNIX Makefile for your project.

Before submitting, to reduce the size of the tar file, type 'make clean'.

To move up from the p2 directory, type

% cd ..
(Additional UNIX commands at the bottom of this page: HOWTO Compile under UNIX)

When you're ready to submit, change the name of the directory to your netid. For example, if your netid is maloofm, then rename the directory p2 by typing

% mv p2 maloofm
Create a tar (tape archive) file of the directory and its contents by typing
% tar -cf p2.tar maloofm
This command creates a tar file named p2.tar containing the directory maloofm/ and the files therein.

Compress the tar file by typing:

% gzip p2.tar
This command will produce a file named p2.tar.gz, which is the gzipped tar file of the directory containing your project. Whew!

To submit the file, type

% submit -a p2 -f p2.tar.gz
p2 is the name of the assignment (-a) and p2.tar.gz is the file (-f) to be submitted for that assignment.

If the program submits the file successfully, you will receive a receipt by e-mail at the address <netid>@georgetown.edu.

Submit your project only once.

Once you've submitted your project, it is important to keep an electronic copy on a university machine (e.g., gusun or cssun). System administrators routinely back up these machines.

You can also change the directory's name back to the original name. For example,

% mv maloofm p2
You can also remove the tar file from your directory:
% rm p2.tar.gz

The TAs who will be grading your projects this semester are listed on the main page. You must submit your project before 5 PM on the due date.

If you're running submit correctly and you see an error message labeled as SEVERE, then execute Plan B by using pine to submit your project as an attachment to an e-mail.

To accomplish this, at the gusun prompt, type 'pine'. When the menu appears, select the menu item for composing messages (C). In the To field, type the e-mail address cosc072maloof@cs. Attach your zip file. Control-T (symbolized ^T) will give you a list of files. Select the file to attach. The subject should be your netid followed by the extension .zip. For example, if your netid is maloofm, then the subject of the e-mail should be maloofm.zip. There's no need to include anything in the MESSAGE TEXT screen.

Once you've entered this information, the screen should look something like the following:

Finally, type ^X (Ctrl-X) to send the e-mail to the course account.