This is a three part project:

  • Part one - build a program that:
    • Prompts the user for a string of user input .
    • Treat that string as a mathematical expression in an infix form.
    • Convert the string into a series of tokens where each token is an operator, or a value delimited by whitespace , operator, or \n
  • Part two -
    • Convert to postfix and print out the results. ( or print out an error if badly formed)
  • Part Three - further.
    • Do the math to evaluate the expression when all operands are values ( not variables)

For this project the operators you will support are:

Plus +
Minus –
Times *
Divide /
Modula %

When I test the program I would expect to see something like this: ( Bold is what I enter on the command line)

Input an expression: A+ B * 31
Tokens: A + B * 31
Postfix: A B + 31 *
Value: Cannot be calculated

Input and Expression: 3+4*12
Tokens: 3 + 4 * 12
Postfix: 3 4 12* +
Value: 51

If the input expression is invalid, print out that fact. Use exceptions to catch any error conditions. (Note - put a space between each Token for clarity)

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.