CS202 Computer Science II
FAQ Newsboard  Telnet Email TA Lectures Assignments Man pages Help

Assignment 2
Due September 28 before 9:00 a.m. in class

Last modified 9/24/98

Background

Here's code for a generalized version of as2 which matches opening "(", "[", and "{" with the corresponding closing characters ")", "]", and "}". It uses a stack module. Note that the stack module needs to be implemented as a class with a default constructor (instead of InitStack()).


Files needed: match.cpp
Turnin instructions. Specific to this assignment: We will need a copy of match.cpp and your script file as2.dat with any input files that you created to test your program design.

What you have to do

You are to implement the Stack class to work with the code above. You need to design the

  1. specification file: stack.h and the
  2. entire implementation file: stack.cpp
Make sure that your Stack implementation works with my code. You cannot modify my code and your Stack class will be tested against my code. In case you didn't know, let me reiterate that the source code should compile and run on any machine with a decent C++ compiler but we must have your handin compiled and running on one of the platforms in the Tompson lab.


Sample Output
% g++ -c -Wall match.cpp
% g++ -c -Wall stack.cpp
% g++ -o matcher -Wall stack.o match.o
% matcher < stack.h
Top-> {  <-Bottom 
Top-> ( {  <-Bottom 
Top-> {  <-Bottom 
()
Top-> {  <-Bottom 
Top-> ( {  <-Bottom 
Top-> {  <-Bottom 
()
Top-> {  <-Bottom 
Top-> ( {  <-Bottom 
Top-> {  <-Bottom 
()
Top-> {  <-Bottom 
Top-> ( {  <-Bottom 
Top-> {  <-Bottom 
()
Top-> {  <-Bottom 
Top-> ( {  <-Bottom 
Top-> {  <-Bottom 
()
Top-> {  <-Bottom 
Top-> ( {  <-Bottom 
Top-> {  <-Bottom 
()
Top-> {  <-Bottom 
Top-> [ {  <-Bottom 
Top-> {  <-Bottom 
[]
Top-> {  <-Bottom 
Top->  <-Bottom 
{}
Top->  <-Bottom 
Everything Matched

Extra Credit

A Challenge

What happens if you have allocated space for 20 elements but the program while running, discovers 20 elements is not enough? Design a constructor and other members to transparently handle this case without signalling that the stack is full.

Talk to me if you have questions