Homework 6: Inheritance

Part 1. By email send a suggested final examination question. The question should either be of the form -- here is a program what does it print or 10 multiple choice questions. In either case the question should be central to a single chapter(either 5, 6, 7, 8, 9 or 10). Unless you have an overwhelming preference use the following rule to formulate a question -- by first letter of last name (a-f: ch5, g-k: ch6, j-o: ch7, p-r: ch8, s-u: ch9, v-z: ch10).This is due May 29.

Part 2. Use inheritance to write a Polish postfix expression evaluator. The root class is to be expression. An expression can either be a constant, a binary operation, or a unary operation. Minimally you need to allow binary plus and times and unary minus and plus.

So 5, 3, +, 6, 7, *, + evaluates to 50. Let P stand for unary plus and M stand for unary minus - write code that can accept a comma separated list of arguments and evaluates them. Extra credit if the function also produces a fully parenthesized infix- equivalent expression.

Think of the base class expression as having a virtual function evaluate. Have two intermediate derived classes -one for binary expressions and the other for unary expressions. Then all the basic terminal classes constitute either a constant expression or a basic operation expression.

An example program using polish prefix will be given out in class. You need to change it to do postfix and extend to include unary operations.

Demonstrate the program by evaluating the above expression - printing out its inputs and its output. Also do the following:

1, M, 7, *, P, 7, 6, +, +

7, 8, 9, *, +, M

7, M, M, 8, +, 0, +

Due Date: In class June 3, 1997

Finally - the final exam will be in class June 5, 1997 4- 5:45. It will cover the text and homework problem from ch1-10. The format will be the same as the first exam- but will be longer. Student submitted questions as is or modified may be used.


Last Modified: 11:25am , May 21, 1997