Question
*Java or C++* The goal of this homework is to build an arithmetic expression TREE (not a stack) for a supplied (hard coded) formula, then
*Java or C++*
The goal of this homework is to build an arithmetic expression TREE (not a stack) for a supplied (hard coded) formula, then traverse the tree to evaluate the expression numerically.
Please use the expression used as an example in slides: A * (B + C) / D
You can use infix, prefix, or postfix notation for the formula. Id suggest using postfix so you can use the tree creation algorithm as described in the slides. The postfix version of the formula is: A B C + * D /
Once you have the tree generated, give the variables integer values for A, B, C, and D, and traverse the tree to calculate the result. There is no need to prompt the user for input, though you can if you want.
For example, if you assign A=2, B=7, C=3, D=5, your result would be 4: 2 * (7 + 3) / 5 = 4
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