Question: Algebraic to RPN Converter / Evaluator - Testcase Hint for comparing precedence of operators: Write a subprogram called prec that you send an operator to

Algebraic to RPN Converter/Evaluator - Testcase
Hint for comparing precedence of operators:
Write a subprogram called prec that you send an operator to and return an integer value for each
precedence level using if statements.
For example, if the operator is + or - then return 1 but if the operator is * or / return 2
This sets precedence of multiplication and division equal to each another and higher than the
other two operators
Then use an if statement comparing the prec(operator in input) to the prec(operator at top of
stack)
1+2
3-4
56
7*8
(2+3)*(4*5)
05
50
2+35+7+3102
Solution: 3
Solution: -1
Solution: 0.83
Solution: 56
Solution: 100
Solution: 0
Solution: Error! Division by 0
Solution: 1
Additional test data from class:
((1+6)*79)-16
((2+3)*10-7-25)
((2*3)+4)-(125)+(3*(53))
3*(105-3)*(7+2)
(12+5)-(36)*10
65-2+(7-4)*(10-5)
Solution: -10.56
Solution: 49
Solution: 12.6
Solution: 135
Solution: 12
Solution: 17
Note: Pseudocode provided does not include state for spaces in input.but testcase above uses them for readability.
If you added additional state for space in input, make sure it does nothing but return back to state 0 and does not
alter the pseudocode in any other way.C programing(beginner level): Increment output string index
Put space in output string
Increment output string index
If stack is not empty, pop left parenthesis off stop of stack but do not put in output string
Otherwise, display error message (mismatched parenthesis) and exit
Next state is 0
State 5: (End of input)
While stack is not empty and character at top of stack is an operator
Pop operator off stack and put in output string
Increment output string index
Put space in output string
Increment output string index
If stack is not empty, display error message (leftover parenthesis) and exit
Otherwise, put end of string marker in output string and send output string to RPN Evaluator
Note: return rpneval(output_string);
State 6: (garbage)
Display error message and exit
Algebraic to RPN Converter / Evaluator - Testcase

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 Programming Questions!