Lab Assignment #2

Due Monday, July 20 at the beginning of class

Got questions? Check out the FAQ for this assignment.

This lab assignment tests your knowledge of implementing and testing a class called Stack. The class will be implemented using arrays. You will implement several Stack operations as specified below.

Operation                       Description

Stack(void);                    Constructor (default)
Stack(int initial_size);        Constructor
void pushItem(int item);        Adds an item to the stack
int popItem(void);              Removes an item from the stack
int peekAtTop(void) const;      Reads item on top of the stack
Boolean isEmpty(void) const;    Checks to see if the stack is empty
Boolean isFull(void) const;     Checks to see if the stack is full
void display(void) const;       Displays the stack on the screen
int getCount(void) const;       Returns the number of items on the stack
int getSize(void) const;        Returns the size of the stack (maximum items that can be placed on it)
The exact specifications for these functions are in a file called stack.h, which you can get from my home directory on PCC's AIX system. (/home/inst/mmead/) It is posted on the class web pages as well. It is very important that you implement these functions exactly as they are specified. There is also a driver module called driver2.cpp that you may use to help you test your program. This driver does not test every possible case, but it is a starting point. You are responsible for making sure that your program works in all cases. I will be using a modified version of this driver to test your functions. The driver code is also in my home directory and posted on the web page. The page is at www.pacifier.com/~mmead/cs162/outline.html

Details

To compile the files on the AIX system into an executable called lab1 you can use this on the command line:
xlC -o lab2 driver2.cpp stack.cpp
If you are not using the Unix system at PCC, you will have to find out how to compile your programs on the machine you are using. As in all programs you write, you should use meaningful identifier names, and the code must be well commented and consistently formatted. Your functions must have appropriate declarations and detailed header comments must explain the purpose of the function, and describe any inputs and/or outputs. Variables should be declared local to the function they are used in. No global variables are allowed, although global constants are permitted.

Back to Outline