Write a stack application program to evaluate post-fix expressions.

The user will enter a post-fix expression of the form

34+ which means 3+4
345+* which means 3*(4+5)
722+- which means 7-(2+2)

as a string. Operators are +, -, and *.
Single digit numbers only. No blanks.
Please note that the expression could be wrong.

e.g.

3+ too few operands (i.e. cannot pop operand)
345 incomplete expression (i.e. more than the result at the end)

Your program will display the evaluated result (a number) or an error message describing what is wrong (the algorithm is in Notes-1, so use it as given).

  • You may assume that no expression will be longer than 12 characters.
  • Since each element of the string is a character, you will need to convert it to an integer to perform arithmetic operations.

Required Test Cases (MUST TEST IN THIS ORDER):

1. 34+ which means 3+4
2. 345+* which means 3*(4+5)
3. 722+- which means 7-(2+2)
4. 34+56++ which means (3+4)+(5+6)
5. 12+34*45+-+ which means (1+2) + ((3*4) - (4+5))
6. 1234567891234 expression too long
7. + too few operands
8. 3+ too few operands
9. 3# invalid element
10. 2345+ incomplete expression

NOTE: Do you think I have listed all possible cases? Always ask yourself if there are other cases you should test to make sure your program is bug free.

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.