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

  Create a program that will calculate the monthly payment

Using the information in the table below, write a program that will calculate the monthly payment based on user inputs of loan amount and number of monthly payments.

  Write a program that will help an elementary school student

Write a program that will help an elementary school student learn multiplication. Use rand to produce two positive one-digit integers. It should then type a question such as: How much is 6 times 7?

  Write a program to show simplified bill

Write a program to show a simplified bill. Customers name, number of hours of labor, and cost of parts and supplies must be entered into program via text boxes.

  Write a program that asks how many tickets sales

Write a program that asks how many tickets sales. Format your dollar amount in a fixed-point notation with two decimal points and make sure the decimal point is always displayed.

  Predict short term movements in stock prices

The work will combine research on a specific problem/technique related to Big Data Processing, implementation of a computing solution and presentation of the results.

  Develop an implementation plan and submit a project proposal

Develop an implementation plan and submit a project proposal - determine a research methodology that integrates research tools and methodologies

  Create a logical expression

Create a logical expression that corresponds to the following statement - Complete the truth table for the expression created.

  Program to calculate cost of purchase-requests from user

Program calculates cost of purchase, requests another item selection from user, and so on. User enters 0 from item menu to quit.

  Explore the game of roulette

Your assignment is to use a random number generator to explore the game of roulette. Despite the true mathematics of the matter, "0" is considered neither "odd" nor "even" when someone bets on the ball landing in an odd or even slot

  Create method to generate random integers

Create a method named posNeg which generates 1000 random integers. Range of numbers must be from -5 to +5 inclusive.

  Cate a function with the first line functionarrayout

create a function with the first line functionarrayout switcherooarrayin this function should take an array of any

  Display the gross earnings-tax payable using program

Print the gross earnings, tax payable, medical levy and net earnings for each employee. At the end of report, print total gross earnings, total tax, total medical levy and total net earnings.

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