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

Learn how to write a postfix calculator program in this comprehensive guide. Understand the logic behind a reverse polish calculator, implement a simple command-line user interface, and support addition, subtraction, multiplication, division, sine, cosine, and square root functions.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/18/2009

koofers-user-ksj-1
koofers-user-ksj-1 🇺🇸

5

(1)

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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.