Question: In C++ Programming exercise: Implement a stack-based program for evaluating arithmetic expressions containing the standard arithmetic operators +,?,?,/, as well as =. The precedence of

In C++

Programming exercise: Implement a stack-based program for evaluating arithmetic expressions containing the standard arithmetic operators +,?,?,/, as well as =. The precedence of the operators is the standard one: ?, / are at the same level of precedence, which is higher than the precedence for +, ? (same level), which itself is higher than the precedence for = (also same level).

Details and suggestions:

Use two stacks, one containing the operators and the other containing the values.

You may use the stack class in the C++ Standard Library or design your own.

The input is a string of alternating integers and operators, separated by one space.

The first and the last element of the input will be a number.

You may assume that the expression contains at most 1 operator of type =.

If it does, it evaluates to either true or false; otherwise, it evaluates to a number. You may use the strtok command to get the operands contained in the input string. Provide an implementation of your algorithm in a file called EE.cpp. The main function should accept the string, parse it, and print out the value it has. Bonus: test the input string and throw the BadExpression exception if needed.

In C++ Programming exercise: Implement a stack-based program for evaluating arithmetic expressions

Test cases (you must make sure your program works on these): On input your program should print out 0.6. On input "12-3*2+?, your program should print out 13. On input your program should print out false. If you are attempting the bonus questi "14 ?= 4-3*2+1?= 16" your program should throw the BadExpression exception. on, on input

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!