CS 112
Homework 5
Due on Wednesday March 6, 2002, by 12:00
a.m. (midnight)
Outline
This homework has three parts: two are technical drills and the third part
is the creative one. The goal is to make sure that
you know how to handle the techical details of developing
programs using the Stack class, in the plain or templated
version, and then apply it to a simple problem: Matching parentheses.
Parts I and II can (and should be) done before the Tuesday
class, possibly with some help from the TAs on the technical
aspects.
For Part III, you should read and understand the problem before
Tuesday's class. I will give you extra hints on it on Tuesday,
should there be a need.
To avoid conflicts (at least in the usage of the makefile) you
must develop each program in a separate directory, and submit
them in separate directories.
Part I
Implementation of a Stack abstract data type
Finish the work started as part of
Thursday's lab, by implementing the class IntStack and testing it
thoroughly
using a menu-based test-driver.
Then create two new stack classes, for character and CustRec
stacks. Provide a single testdriver for all three of them.
Part II
Templated Stack.
Using the templated stack skeleton linked to from Lecture 10,
develop a program that fully implements the class and tests it on
three
types of stacks: integer, character and Customer Record.
Part III
Matching parentheses
Implement a class called Paren (from "parentheses"), which
handles correctly parenthesized expressions. Such an expression
(a "Paren") is stored as an array of characters, and manipulated
via class-specific functions. The constructor initializes an
empty Paren expression. The function Input reads in from the user
an expression and checks that it contains only the 6 types of
characters
allowed (open and closed parentheses of three types, (), [] and
{}).
The function Print prints the expression. The function Match
verifies that the expression is correct (all the parentheses match).
To test the class, you will implement a testdriver. Submit all
the files (h and cpp), a makefile, a data file and a typescript.
Submit as follows:
- Using submit Hw5I:
IntStack.h, IntStack.cpp, CharStach.h, CharStack.cpp,
CRStack.h, CRStack.cpp. testStack.cpp, Makefile and typescript
- Using submit Hw5II:
stackT.h, stackT.cpp, testStackT.cpp, Makefile and
typescript.
- Using submit Hw5III:
All the necessary files (h and cpp), a Makefile, a data file and
a 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.
Grading guidelines
- Part I and Part II, done perfectly, will get you a grade of B.
- To get a grade in the A category, you must do Part III. A
working program with static testing (i.e. similar to the one
linked to from the lecture notes)
is worth an A-.
For an A, you
must design a better (menu-based) test-driver, which will allow
the user to choose which function to test next.
- A clarification: the menu-based testdriver should NOT have
options for constructor(s). It should statically allocate a
variable of Paren type, and apply on it the functions chosen
by the user (via the menu-based interface)
Ileana Streinu