Implement the algorithm for evaluating postfix expressions

Assignment Help C/C++ Programming
Reference no: EM131137864

Programming Problem C++:

Write a program to implement the algorithm for evaluating postfix expressions that involve only singledigit integers and the integer operations: +, - , *, and /. To trace the action of postfix evaluation, display each token as it is encountered, and display the action of each stack operation.

Your program should output an error message if the postfix expression is not well formed. I.e. not correct. For example given the expression 9 2 1 + / 4 * the output of your program should resemble the following: Token = 9 Push 9 Token = 2 Push 2 Token = 1 Push 1 Token = + Pop 1 Pop 2 Push 3 Token = / Pop 3 Pop 9 Push 3 Token = 4 Push 4 Token = * Pop 4 Pop 3 Push 12 Token = Pop 12 The algorithm for evaluating postfix expressions is given below. ALGORITHM TO EVALUATE POSTFIX EXPRESSIONS Each time an operand is encountered, it is pushed onto the stack.

When an operator is encountered, the top two values are popped from the stack, the operator applied to them, and the result pushed back onto the stack.

The following algorithm summarizes this procedure:

1. Initialize an empty stack

2. Repeat the following until the end of the expression is encountered: a) Get the next token (character, variable, arithmetic operator) in the postfix expression.

b) If token is an operand, push it onto the stack. If it is an operator, do the following:

i) Retrieve and pop the top two values from the operand stack. If the operand stack does not contain two items, an error due to a malformed postfix expression has occurred and evaluation is terminated.

ii) Apply the operator token to these two values. iii) Push the resulting value back onto the operand stack.

3. When the end of the expression is encountered, its value is on top of the stack (and in fact must be the only value in the stack).

Reference no: EM131137864

Questions Cloud

A random sample from a normal population : Let X1 and X2 constitute a random sample from a normal population with σ2 = 1. If the null hypothesis μ = μ0 is to be rejected in favor of the alternative hypothesis μ = μ1 > μ0 when x > μ0 + 1, what is the size of the critical region?
Determine the degree of saturation at the maximum dry unit : Determine the maximum dry unit weight and the optimum water content.
Explain the elasticity of demand for products : Analyze the elasticity of demand for products within the selected industry relevant to Katrina's Candies. Determine the factors involved in making decisions about pricing these products that you believe to be the most influential.
A single observation of a random variable : A single observation of a random variable having a uniform density with α = 0 is used to test the null hypothesis β = β0 against the alternative hypothesis β = β0 + 2.
Implement the algorithm for evaluating postfix expressions : Write a program to implement the algorithm for evaluating postfix expressions that involve only singledigit integers and the integer operations.
Pearson lemma yields the critical region : A random sample of size n from a normal population with σ2 = 1 is to be used to test the null hypothesis μ = μ0against the alternative hypothesis μ = μ1, where μ1 > μ0. Use the Ney man-Pearson lemma to find the most powerful critical region of size α..
What are the total estimated manufacturing costs : Amity Plastic Manufacturing is a small plastic products manufacturer. The company uses machine-hours as the single, plant-wide predetermined cost driver rate to allocate manufacturing support costs to the various jobs contracted during the year, W..
Can ticket scalping be justified : Ticket scalping is common for popular games. Can ticket "scalping" be justified? Post opinion using aggregate demand and supply analysis.
Use the ney man-pearson lemma to indicate : Use the Ney man-Pearson lemma to indicate how to construct the most powerful critical region of size α to test the null hypothesis θ = θ0, where θ is the parameter of a binomial distribution with a given value of n, against the alternative hypoth..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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