Task Description
Some hp
calculators, such as the 12c, use an entry system logic
called RPN. Sometimes this is called the ‘enter method’
because the calculator has no EQUAL key, but uses an
ENTER key instead. Many scientists and engineers prefer
this entry system logic. You will write a program to
process RPN expressions.
In summary, RPN
does not use parentheses, and operators (like plus and
minus) follow their operands. A few examples are shown
below:
Algebraic Expression 
RPN 
3 + 5 
3 5 + 
6 * (
7 + 8 ) 
6 7 8
+ * 
( 9 +
5 ) * ( 7 + 8 ) 
9 5 +
7 8 + * 
( ( 4
* ( 2 – 3 ) ) / ( 5 – 6 ) 
4 2 3
– * 5 6 – / 
Program Input
Each line of the
input file (prob12.in) contains a series of numbers and
operators. The program must evaluate these lines as RPN
expressions. All tokens are separated by one or more
spaces. Numbers may be negative. Valid operators are
+(addition), (subtraction), *(multiplication) and
/(division). The last line of the file contains only the
word END:
16 3 7 + *
4 32.125 13 – * 20 +
5 –3 * 4 2 / 6 3 1 – / + +
END
Program Output
The program will
print the computed result of each RPN expression on a
separate line.
160
96.5
10
