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.
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 inputStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started