Write a program that accepts simple rpn statements as input

Assignment Help Programming Languages
Reference no: EM131663681

Assignment

Problem Description

When working with basic arithmetic operators such as addition, subtraction, multiplication and division, there is sometimes the need to add parenthesis to force the order of operations. This is true in both mathematics and when programming. However there is an alternative. Jan Lukasiewicz, a Polish logician and philosopher, invented in the 1920s what is now known as prefix notation, also known as Polish notation due to the nationality of Lukasiewicz. Later in the 1950s, several computer scientists created postfix notation, which is also known as Reverse Polish Notation (RPN).

During the 1970s and 1980s, Hewlett-Packard made calculators that accepted input in RPN. This influenced a generation of engineers who relied upon those calculators.

You will write a program that accepts simple RPN statements as input, performs the requested calculation, and prints the result to the console.

Reverse Polish Notation

Consider the expression "a + b". This is in standard algebraic notation, also know as infix notation because the addition operator appears in between the a and b. The same expression in RPN is "a b +". As mentioned above, RPN is also known as postfix notation because the addition operator appears after its operands of a and b. By contrast the expression "+ a b" would be in prefix notation.

The benefit of RPN is that parenthesis are not needed. Consider the expression "a * (b + c)". This is written in RPN as "a b c + *". This is evaluated by reading the expression from left to right. When an operator is encountered, in this case the first is addition, the two most recently seen values are the arguments. The result is then substituted in place and processing of the expression continues until the end.

For reference, you have likely encountered RPN previously and did not know it. For example, the factorial function (i.e. 3! = 3 * 2 * 1) is written in RPN.

Your Program

Your program will read in simple RPN expressions and calculate the result. Full processing of a RPN expression is a bit beyond where we are now, so we will only deal with simplified single operator expressions. That is, you will need to take as input two numbers and one character.

The operations you need to support are addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^).

Reference no: EM131663681

Questions Cloud

Password on a cisco router in your internetwork : What would you implement to facilitate password recovery of a lost enable password on a Cisco router in your internetwork?
How do you explain the potential for home-based services : Are LTC services provided in the home or community less expensive than those provided in an institutional setting
Access the services outside their own subnet : How would you design a LAN if you have different groups of users who should not access the services outside their own subnet?
Norton ghost utilize to install windows 8 : You want to ghost your network's computers with a fresh desktop that features Windows 8, as your computers currently use Windows 7.
Write a program that accepts simple rpn statements as input : Write a program that accepts simple RPN statements as input, performs the requested calculation, and prints the result to the console.
Practice the palpation and auscultation a few times : It is important for you to be comfortable with the normal in order to know what is abnormal
Balance supply with demand to maximize profitability : Define predictable variability and provide an example on how companies can respond in predictable manner to balance supply with demand to maximize profitability
Prepare pseudocode for a program : Prepare pseudocode for a program that lets a user continuously enter numbers until a number less than 0 is entered.
Show how the breakeven point in units changes : Sales mix, new and upgrade customers. Chartz 1-2-3 is a top-selling electronic spreadsheet product. Chartz is about to release version 5.0.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd