Question: Write a C program that takes as input a fully parenthesized, arithmetic expression of binary operators + , , * , / , and converts
Write a C program that takes as input a fully parenthesized, arithmetic expression
of binary operators and converts the expression into a binary expression
tree. Your program should take input from the command line. The entire
expression should be in a character string without any space in it
An input string only includes floating numbers in the format of YYY that is one
digit to the left of the decimal point and two digits to the right of the decimal
point, and variables of the form of x x x
Your program shall allow for the leaves in the expression tree not only to store
floating values but also to store variables of the form x x x For example,
expression xx x will be converted into a binary expression
tree like:
x
x x
Your program should then show a menu with the following options:
Preorder
Inorder
Postorder
Calculate
Exit
Description:
a If an option of Preorder, Inorder, or Postorder is selected, your
program should print the expression by the corresponding traversal
order Note: no parentheses for preorder and postorder traversal but
fully parenthesized for inorder traversal
b Arithmetic calculation is invoked by option Calculate. Your program
should be able to detect errors like dividebyzero before the
calculation.
This option supports both expressions with and without
variables. The program first checks for any dividebyzero errors
before calculation.
If the expression contains variables, the program prompts the
user to input values for each variable in floatingpoint format
YYY Once all variable values are entered, they are
substituted into the expression. If a variable for any reason is not
defined or found, the program may use as the default value for
the variable. Appropriate messages should be displayed to the
users to inform this.
The program then evaluates the expression and provides the
answer in floatingpoint format YYY
If theres an error in the calculation such dividing by or
unknown operator, the program shall display appropriate
messages and the calculate function can return and output
c Option Exit terminates your program.
Note: No more than variables will be passed in a given expression
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
