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.

  1. 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 /
  2. A constructor, initializing the expression to, say, the string "0".
  3. A member function for initializing the array by reading the expression from the standard input.
  4. A member function for printing the expression to the standard output.
  5. 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.
  6. Design a test driver for your class. Test your program on a few arithmetic expressions with at least 5 operators.
  7. 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!
Naming conventions and files to submit (in Hw6):

Ileana Streinu