ASSIGNMENT:

Create a program, which will read a series of numbers and operators. Using those values a tree will be built representing the expression. The tree will then be evaluated and deleted.

STATEMENTS:

Valid statements are of one of the following three forms:

  • 'C' followed by a whole number: this will cause the number (up to three digits with a possible minus sign) to be inserted into the tree as a constant.
  • 'V': The letter V followed by two digits will cause a variable to be placed into the tree (the digits will be which variable 00 through 99).
  • 'v': The letter v followed by two digits, a space, and up to three digits with possible minus sign will set the value of a variable (the set of two digits is which variable) to be set to the value (the set of up to three digits).
  • 'O' followed by an operator (+, -, *, /) followed by a single digit number: this will insert the operator into the tree using the following digit as the precedence of the operator (this equates to the number of parentheses enclosing the operator - the higher the value of the number, the higher the precedence of the operator).
  • 'E': The letter E will cause the tree to be evaluated and the resulting value printed.
  • 'D': The letter D will cause the tree to be deleted.
  • 'X': Terminate the program.

For test purposes some way of printing the delete operation as it proceeds should be provided to insure that all nodes are indeed deleted.

After deleting the tree, the process may begin again and will result in the creation of a new tree.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.