CS 342 Lab 3: Bounded Stack Class

 

http://classes.cec.wustl.edu/~cs342/current-semester/lab/lab3/

Lab date: 8-10 February 2000
Due date: Sunday 13 February 2000 11:59 pm

Objective:

A stack is a simple data structure that enforces a LIFO (last-in, first-out) policy to manage its data elements. In this lab, you will utilize your Array class from the previous lab to implement a Stack class. Specifically, you will implement a bounded Stack class, whose maximum size is fixed at the time of creation.

Preparation:

  1. Review the header file for the Stack template class (Stack.h) that is part of the distribution for this lab. Do not vary from this specification.

  2. If necessary, review your CS101/CS241 notes to recall what a stack is.

Assignment:

Given a specification for a Stack class, write the methods and operators for that class. The class represents an ADT with operations such as push, pop, top. is_empty, and is_full. Use your Array class for the implementation, which should make the Stack implementation straightforward.

A test driver program is supplied (main.cc) but you must extend it to completely test your implementation. Your implementation must check for error conditions, such as attempting to pop off an empty stack or push on to a full stack, and failing to allocate dynamic memory. And be sure to test all of the methods, including read.

Special Note: Be sure that push, pop, and top check whether the stack is empty or full, as appropriate. They return 0 for success, or -1 if the stack was already full when attempting to push, or empty when attempting to pop or top.

Obtaining the Lab 3 distribution:

At a Unix shell prompt, type ~cs342/bin/lab3. That will copy several files to a new lab3 subdirectory. You can cd lab3 and enter make to compile the code, if you like. However, it will not link until your implementation is filled in.

NOTE: you can use the distribution mechanism to revert one or more of your files at any time. First, delete the file (or better, mv it to a file with a different name, such as Stack.cc.BAD). Then, run cvs update to update your workspace. That will replace any missing files. It will also let you know of any files that you modified but did not delete. cvs is in pkg gnu, in case you don't find it at first.

After obtaining the Lab 3 distribution, copy your Array.h and Array.cc files from your Lab 2 to your lab3 directory. You should use those files without modification. However, you may fix bugs in your Array implementation.

A Stack.cc file is included. Fill in this file, and add any necessary code to the private section of Stack.h to complete the assignment.

What to Submit:

By the due date, submit all source files from your final solution. Include a laboratory writeup file (named readme) documenting what you did to satisfy this assignment. readme contains a suggested list of sections that you might provide. Please replace the comments in [] with your descriptions. Specifically mention what the most troublesome parts were. These files will be submitted automatically when you execute the command:
make turnin
NOTE: there is a Makefile target that allows you to test what you are going to turn in:
make test_turnin

It places the output that will be turned in into the TEST_TURNIN directory. Please use make test_turnin, and verify that the files that you will submit are correct.


Please see the Lab 2 assignment for hints on compiling templates.


CS 342 home page