Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Private member elements: A vector of structs named symbolTable where the struct contains 2 fields: name ( type string ) and value ( type double
Private member elements:
A vector of structs named symbolTable where the struct contains fields: name type
string and value type double
Methods Implement the following functions:
Implement the makeExpTree functions that accepts an exp as a string argument and
create expTree.
A bool function named readSymbol that accepts a filename string as argument and read
data from a file where each row has two values: a symbol name string and a value
double Function heading:
bool readSymbol string fname
Function return true if file is opened successfully, false otherwise.
A lookup function that accepts two arguments: string and value as show below:
bool lookup string name, double & value
function find the value from the symbolTable matching that of the given name. It return
false if the name is not found in the table.
A double function named eval that evaluates the expression tree and assign result to the
reference argument. This evaluation should handle expression with a mix of numbers in
string form and variables whose value can be found in symbolTable. Function heading:
bool eval double & result;
function return the true if eval is successful, false otherwise. For this assignment, we will
assume that the expression is grammatically correct. As such, the only error will be the
result of missing symbol which is identified by the lookup function. A straightforward
implementation is to call a recursive version of the eval function that does all the work. It
will have the following heading:
bool evalnode string double& result;
Sample IO
Create an appropriate main function that will test all the new features. For example, the main
could first read the data from a file by calling readSymbol. It then continue to ask user for infix
expression, create an exp tree and then call eval to evaluate and print the result.
Required Data Structure
You MUST use ExpTree class which derives from binary tree base class.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started