COSC 072: Computer Science II

Project 2
Spring 2008

Due: Feb 22 @ 5 PM
6 points

In lecture, we are developing the Stack<T> and Queue<T> classes using the Node<T> class.

If you haven't already, get Node<T> implemented, running, and tested.

Next, implement the Stack<T> class and then the Queue<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. Methods of both classes should throw appropriate exceptions, such as bad_alloc, StackEmpty, and QueueEmpty. Use constant parameters and constant methods as appropriate.

One can never get enough pasta, so we'll be reusing (don't recycle) the Pasta class from p1. Oh! Joy! However, for this project, you must overload the stream insertion and stream extraction operators for Pasta objects...No more Pasta::read. That is, implement operator<< and operator>> for Pasta. Take a cue from Complex...simple.

You'll be creating and stress testing a stack of pasta and a queue of pasta. (For some reason, stack of pasta sounds better.) Your main should take a file name from the command line—I'll show you—and read from it. The file will contain commands that designates the container—S or Q for stack or queue, respectively—the operation on that container (i.e., (I)nsert, (R)emove, and (G)et), and then the pasta object, which will consist of a length and a name. For the stack, insert means push, remove means pop, and get means top. For the queue, insert means enqueue, remove means dequeue, and get means front. For remove and get operations, the main function should write removed and "gotten" Pasta objects to cout.

For example, consider the following sequence of commands:

S I 6 lasagna
Q I 6 spaghetti
Q R
S G
The first command pushes (inserts) the lasagna object onto the stack. The second enqueues (inserts) spaghetti. The third dequeues (removes) the object at the front of the queue, while the fourth command gets or returns the object at the top of the stack, which is lasagna.

The output for this input file would be:

6 lasagna
6 spaghetti
6 spaghetti
6 lasagna
After executing these commands, the queue would be empty, and the stack would contain lasagna.

Naturally, if there is an attempt to perform an operation on a empty container, such as get or remove, then the method corresponding to that operation should throw an appropriate exception, which main should catch and report. Processing should continue. Stack and Queue must be template classes and each must implement a copy constructor, overload the memberwise copy operator, implement a clear method, and a destructor. (Not deconstructors! That's POMO. This is C++.)

Feel free to submit your own test file(s), but we'll be using our own. main should handle incorrect arguments, invalid filenames, incorrect container commands, incorrect manipulation commands, bad allocations, operations on empty containers, and pasta lengths that are out of range. main should catch and report these errors and continue processing.

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, if appropriate.

Getting Started

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. To get started, first create the p2 directory in $HOME:
seva% cd ~
seva% mkdir p2
seva% cd p2
Now copy the Makefile from my directory:
seva% cp ~maloofm/cosc072/Makefile ./
Groovy. Since you'll need your Pasta class for this project, you need to copy that over. If pasta.cc and pasta.h are in the directory $HOME/p2 $HOME/p1, then type:
seva% cp ../p2/pasta.* ./
seva% cp ../p1/pasta.* ./
That should copy over the source and include files, and perhaps the .o.

Next, type:

seva% touch Makefile.dep
If you're coding on a Windows machine, you may need to edit the Makefile and change the .cc extension to .cpp. Further instructions are in comments at the top of the Makefile and we'll discuss how it works in class.

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

/*
 * 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.
 */

Instructions for Electronic Submission

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 project's directory.

Assuming all of your code is in the subdirectory p2, directory, this directory and the submit program should be in the same directory:

seva% ls
p2/ submit.jar

To reduce the size of the zip file, before submitting, remove all object and executable files:

seva% cd p2
seva% make clean

If you need to include a message to your TA or me about your submission, then place the message in a file named README. Place the README file in the project's directory.

To move from the p2 directory to the parent directory, type

seva% cd ..
At this point, you should be above the p2 directory:
seva% ls
p2/ submit.jar

(Additional useful Unix commands)

When you are 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

seva% mv p2 maloofm
Create a zip file of the directory and its contents by typing
seva% zip -r p2.zip maloofm/*
This command creates a zip file named p2.zip by recursively (-r) copying all of the files (*) from the directory maloofm/.

To submit the zip file type

seva% java -jar submit.jar -a p2 -f p2.zip
p2 is the name of the assignment (-a) and p2.zip 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., seva) that preserves the modification date and time. If we lose your project or the submission system breaks, then we will need to look at the modification date and time of your project to ensure that you submitted it before it was due.

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

seva% mv maloofm p2
Note that changing the name of the directory does not change the dates of the files in the directory. You can also remove the zip file from your directory:
seva% rm p2.zip

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

Plan B

Submit is pretty reliable, but it is software. If you're running submit correctly and you see an error message labeled as SEVERE, then it's time to execute Plan B by using mail to submit your project.

To accomplish this, assuming the file you want to submit p2.zip, type at the seva prompt

seva% uuencode p2.zip p2.zip | mail cosc072@cush.georgetown.edu
Briefly, uuencode encodes the binary file p2.zip as an ASCII file that can be transmitted as mail. This form of the uuencode command pipes the ASCII-encoded file through standard input and into (|) the mail command.

When we receive you mail, we will save it to a file and use uudecode to translate the ASCII-encoded file back to the original binary file. Virtually all mail clients automatically encode binary files in this way.

Please don't use this account for communication. We don't check it regularly.

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