CS 112
Homework 5

Due on Wednesday March 7, 2001, by 12:00 a.m. (midnight)


Implementation of a Stack abstract data type

Overview of the homework

You have to implement the functions (methods) in the Stack class. The code is very simple. First, you implement a stack of integers. Then modify the class to turn it into stacks of various other types (characters, records of type CustRec).
Part I, with 4 separate programs and compilations, should be finished before the Tuesday class (so that we can discuss it in class), but I will not verify this formally. You can, however, continue to work on it afterwards and submit the best solution you complete by the Wednesday deadline.
You have to do this part, and submit all these files separately: this is teaching you how to do several compilations with one Makefile. But as you may have guessed, templates should be used here. This will be done in Part II.

On Tuesday in class I will show you how to combine classes with templates and you will do the second part of the homework, creating a general templated Stack class that should work for all of these data types.

Part I

  1. Implement the stack abstract data type in C++ following the model shown in class. You can start by copying the models I made available here.
  2. Then perform the following simple modifications: implement an abstract data type for a stack of characters (not integers). Name your class CharStack and the testdriver testCharStack. Design a test driver for it, too. (You can do it by performing simple modifications on the test driver for stacks of integers.)
  3. The same, for a stack of CustRec records (the same data structure we used to illustrate templates in C++).
  4. Design a testdriver to test all the three stacks above. You should be careful with the makefile, which will contain 4 different compilations (three for the three classes, one for the main program).

Part II

Design a Stack templated class, and test it on the same three types of stacks you did before (integers, characters and CustRec-ords). Use the notes from lecture 11, more precisely the models available in the TemplateStack directory (but you should design a better testdriver).
See instructions below on how to name the files for this homework, and how to submit.


Files to submit (for all C++ homeworks)

Header file, all cpp files (class and testdriver), the Makefile and a typescript.

In other words, everything that is needed to recompile you program (source code and Makefile), and a proof that it really works and is fully tested (typescript).

For this homework, particular emphasis will be placed on testing, therefore make sure you have tested ALL the functions in your class on significant cases. You do not need to submit a data file, and you do not need to all obey to the same type of user interface. You may design a user interface to test your programs, if you want. That would count as extra credit.
Ileana Streinu