Question: 1(a) Complete the definition for the C++ function int evalTree(const cse250::tNode * exprRoot); that returns the result of evaluating the expression stored in the tree

1(a) Complete the definition for the C++ function

int evalTree(const cse250::tNode* exprRoot); that returns the result of evaluating the expression stored in the tree rooted at exprRoot.

1(b) Complete the definition for the C++ function

 void exprToString(const cse250::tNode* exprRoot, std::ostringstream& output); 

which stores in output the fully parenthesized expression stored in the tree.

Parentheses should not be included for single node expression (as illustrated in the example).

Parentheses should be included around each operator and its operands, even if the consecutive operators are the same.

E.g.: -42, (5*-8), (4+(3+5)), ((2*3)*4)), (-3+10), etc.

The order of the parenthesization is based on the tree.

No spaces should be inserted.

output is initially empty.

Submission: Submit your code for both parts of this problem in the file a4-expressions.hpp to A4 Programming - Expressions on Autolab.

Allowed headers:

In a4-expressions.hpp, you may only include: "tNode.hpp" and

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!