CSE 335 Homework 3
Objectives:
Implement class hierarchies using abstract classes and pure virtual functions.
Description:
In class, we discussed how to design a class hierarchy to implement arithmetic expres-
sion trees. For this exercise, you are to implement these classes and add an operation to compute
the value of an expression tree. For the first part, you will need to implement the concrete classes:
Literal
represents an integer literal in an expression (e.g., the “23” and the “3” in the expression
23
-
3
).
Negate
is a unary operator that changes the sign of another expression (e.g., in the expression
-
(23 + 4)
the primary operator is negation).
Add, Subtract, Multiply, and Divide
are binary operators whose names should be self explana-
tory.
Initially, class
Literal
should merely provide an operation for returning its value, and the operator
classes should provide operations for retrieving the expression or expressions upon which they
operate.
This is the end of the preview.
Sign up
to
access the rest of the document.
- Fall '08
- Kraemer
- Algebra, operation, virtual functions
-
Click to edit the document details