Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this lab you will be creating a prefix calculator. The user will enter an expression in prefix form and your program will calculate and

In this lab you will be creating a prefix calculator. The user will enter an expression in prefix form and your program will calculate and display results. An expression in prefix form states the operation to be performed before the operands. For example the prefix expression: +23 means that the operation to be performed is addition, the operands are 2 and 3. Therefore, the result of the calculation will be 5. Prefix notation is widely used in functional programming languages. Some additional expressions and their equivalent in traditional infix form (with operator in the middle are shown below.)
Prefix Form
Infix Form
Result
20-30
20+(-30)
-10
24
2*4
8
74
7-4
3
/227
22/7
3
/210
21/0
NaN
All operations are integer operations for this Lab. Note the division operation in particular. In addition to the operations listed above, you will also support abs operation which will compute the absolute value of the given number. The following examples show how the calculator will run. You can break the user input by using the split function to separate the operands and operators from the input string. You must detect possible division and report it.In this lab you will be creating a prefix calculator. The user will enter an expression in prefix form and your program will calculate and display results. An expression in prefix form states the operation to be performed before the operands. For example the prefix expression: +23 means that the operation to be performed is addition, the operands are 2 and 3. Therefore, the result of the calculation will be 5. Prefix notation is widely used in functional programming languages. Some additional expressions and their equivalent in traditional infix form (with operator in the middle are shown below.)
\table[[Prefix Form,Infix Form,Result],[+20-30,20+(-30),-10],[***24,2**4,8],[-74,7-4,3],[?227,227,3]]
All operations are integer operations for this Lab. Note the division operation in particular. In addition to the operations listed above, you will also support abs operation which will compute the absolute value of the given number. The following examples show how the calculator will run. You can break the user input by using the split function to separate the operands and operators from the input string. You must detect possible division and report it.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managerial Economics and Business Strategy

Authors: Michael R. baye

7th Edition

978-0073375960, 71267441, 73375969, 978-0071267441

Students also viewed these Databases questions

Question

What language do they use?

Answered: 1 week ago

Question

Evaluate three pros and three cons of e-prescribing

Answered: 1 week ago