CS 112
Homework 6
Due: Wednesday 11/1/2000 by 12:00 a.m.
To Do
Implement in C++ a class ArithExpr for a very restricted form of
arithmetic
expressions in postfix form. The class should have the following structure.
- As private members of the class, an array of characters (where the
arithmetic expression is stored as a sequence of characters) and its length.
Your expressions will be built up from atoms which are "numbers"
made of only one decimal digit
(0 through 9) and the arithmetic operators +, -, * and /
- A constructor, initializing the expression to, say, the string "0".
- A member function for initializing the array by reading the expression
from the standard input.
- A member function for printing the expression to the standard output.
- A member function for evaluating the arithmetic expression, using the
algorithm described in class. This should
make use of one of the Stack classes
that you created and tested in Hw 5.
Careful: the expression is a
sequence of characters, but the values you push on the stack, some resulting
from performing an arithmetic expression, are integers. You might have to do
some type casting here (converting a character
representing a digit into the appropriate integer value). We will
discuss this in class, if there are confusions about this part.
- Design a test driver for your class. Test your program on a few arithmetic
expressions with at least 5 operators.
- To simplify the interface, I will provide the test data.
The data file is available here,
or you can copy it from the class account in the
~112a/handout directory. Notice that each arithmetic expression
ends with a dot, and the file ends with a dot on one line
(i.e. when you read in an expression and its length is 0, you
know it is the end).
Submit in hw6 all the files: sources, Makefile and a
typescript. See below for naming conventions. Test your
program on all the arithmetic expressions illustrated by the
applet shown in class (look in the Java console).
Extra Help
For this assignment, I am providing extra help for those of you
who might need it. Please take advantage of it!
- If your Stack classes from Hw5 are not entirelly tested, you
can use the ones I have made available to you in class (header
and object files). Using these files will not result in any
penalty on your grade.
- If you find that, while working on your homework, you have
trouble with some other minor auxiliary functions, such as reading
the arithmetic expression from the standard input, you will have
to email me and I will make
the code for such a function
available to you (with a small penalty on your grade, though).
- I am also available in class on Thursday for those of
you who need help with the overall design of the program: class
description and header files, testdriver, Makefile. The only
function for which I will not give you explicit help with the
code (besides what
was already discussed in class) is the Eval function, for the
evaluation of the arithmetic expressions. But of course, I can
help you with debugging.
Naming conventions and files to submit (in Hw6):
- Stack of integers: IntStack.cpp, IntStack.h
- Arithmetic expression: ArithExp.cpp, ArithExp.h
- Test driver: testAE.cpp
- Makefile
- Data file: data
- typescript
Ileana Streinu