Docsity

Postfix Calculator Program: A Step-by-Step Guide, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
Write a program that simulates a postfix (a.k.a. “reverse polish”) calculator. In this calculator,
you enter a number, press “push”, enter another number and press “push”, then press the
button of the operation, such as addition. For example:
10.1 <push>
15.4 <push>
<+>
25.6
•Your calculator must support addition, subtraction, multiplication, division, sine, cosine, and
square root.
•To implement this program, you must read from the keyboard and display to the console. You
must not build a GUI for this program. Therefore, you need a simple, command line user
interface. When a user enters a number (and presses the “enter” key), you will push the number
on a stack. When a user enters a function (either one of the operation keys, “+”, “-“, “*”, or “/”) or
a function name (“sin”, “cos”, or “sqrt”), you will pop the operands off the stack, execute the
operation, then push the result on top of the stack. You should display the top of stack after
each operation.

Partial preview of the text

Download Postfix Calculator Program: A Step-by-Step Guide and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

Write a program that simulates a postfix (a.k.a. “reverse polish”) calculator. In this calculator, you enter a number, press “push”, enter another number and press “push”, then press the button of the operation, such as addition. For example: 10.1 15.4 <+>

•Your calculator must support addition, subtraction, multiplication, division, sine, cosine, and square root. •To implement this program, you must read from the keyboard and display to the console. You must not build a GUI for this program. Therefore, you need a simple, command line user interface. When a user enters a number (and presses the “enter” key), you will push the number on a stack. When a user enters a function (either one of the operation keys, “+”, “-“, “*”, or “/”) or a function name (“sin”, “cos”, or “sqrt”), you will pop the operands off the stack, execute the operation, then push the result on top of the stack. You should display the top of stack after each operation.