Question: In this lab, you'll implement a simple calculator and equation converter. It'll parse expressions written in [ reverse Polish notation ] [ rpn ] .

In this lab, you'll implement a simple calculator and equation converter. It'll
parse expressions written in [reverse Polish notation][rpn]. Then, depending on
a command line argument, it will do one of the following:
Print the expression in [Polish notation][pn].
Print the expression in reverse Polish notation.
Evaluate the expression and print the result.
Your calculator should operate on 'double's and support the following operators.
"+ adds two numbers (34+ is ).
"-" subtracts one number from another ( is -4').
"*" multiplies two numbers (27**2 is '14').
" divides one number by another (7-4? is {:?'-1.75).
'%?' returns the remainder after dividing one number by another (0.70.3% is '0.1').
negates a single number (8 is ?'-8').
Your calculator should read one line of input at a time, print some output, then
move on to the next line. It should exit when it reaches the end of the input.
Use 'Ctrl+D' to simulate this on Mac and Linux, or "Ctrl 1+Z' followed by "Enter'
on Windows.
Definitions
All the following examples are representations of this equation, written here in
standard (infix) notation. It evaluates to 67.5.
(12+3)**(5+42)
Polish Notation
In Polish notation, also known as prefix notation, the operator comes before its
arguments.
**+123+542
In reverse Polish notation, also known as postfix notation, the operator comes
after its arguments.
In this lab, you'll implement a simple calculator

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!