subject

C++ PLEASE :We commonly write arithmetic expressions in infix form, that is, with each operatior placed between its operands, as in following expression.(3+4)*(5/2)Although we are comfortable writing expressions in this form, infix form has the disadvantage that parentheses must be used to indicate the order in which operators, in turn, greatly complicate the evaluation process. Evaluation is much easier if we can simply evaluate operators form left to right. Unfortunately, this evaluation strategy will not work with the infix form of arithmetic expressions. However, it will work if the expression is in postfix form. In the postfix form of an arithmetic expression, each operator is placed immediately after its operands. The expression above is written in postfix form as:3 4+5 2/*.Note that both forms place the numbers in the same order. The order of the operators is different, however, because the operators in the postfix form are positioned in the order that they are evaluated. The resulting postfix expression is hard to read at first, but it it’s easy to evaluate. All you need is a stack on which to replace intermediate results. Suppose you have an arithmetic expression in postfix form that consists of a sequence of single digit, nonnegative integers and the four basic arithmetic operators. This expression can be evaluated using the following algorithm in conjunction with a stack of floating -point numbers. Read in the expression character-by-character. As each character is read in:If the character corresponds to a single digit number (character’s 0 to 9)then push the corresponding floating-point number onto the stackIf the character corresponds to one of the arithmetic operators (+,-,*,/) thenPop a number off of the stack. Call it operand1.Pop a number off of the stack. Call it operand2.Combine these operands using the arithmetic operator, as follows:Result= operand2 operator operand1Push result onto the stackWhen the end of the expression is reached, pop the remaining number off the stack. This number is the value of the expression. Applying this algorithm to the arithmetic expression: 3 4 + 5 2/*Yields the following computation:‘3’: Push 3.0‘4’: Push 4.0‘+’: Pop, operand1= 4.0 Pop, operand2=3.0 Combine, result= 3.0+4.0=7.0 Push 7.0‘5’: Push 5.0‘2’: Push 2.0‘/’: Pop, operand1=2.0 Pop, operand2=5.0 Combine result=5.0/2.0=2.5 Push 2.5‘*’: Pop, operand1=2.5 Pop, operand2=7.0 Combine, result=7.0*2.5=17.5 Push 17.5‘\n’: Pop, Value of expression=17.5Step 1: Create a program that reads the postfix form of an arithmetic expression, evaluates it, and outputs the result. Assume that the expression consists of single-digit, nonnegative integers and the four basic arithmetic operations. Further assume that the arithemetic expression is input from the keyboard with all the characters separated by white space on one line. Save your program in a file calles postfix. cppStep 2: Complete test plan 6-2 by filling in the expected result for each arithmetic expression. You may wish to include additional arithmetic expressions in this test plan. Step 3: Execute the test plan. If you discover mistakes in your program, correct them and execute the test plan again.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 18:30
How often does colleges update the cost of attendance on their website? . a)every two years b) every four years c) every year d) every semester
Answers: 1
question
Computers and Technology, 24.06.2019 07:00
Why would a business likely use a java applet - to back up their data files for the business - to create a program that a customer can launch in their web browser - to create music on a powerpoint presentation - to organize files on their company directory
Answers: 3
question
Computers and Technology, 24.06.2019 15:30
During the software planning process, rick, a project manager, finds that his team has made an incorrect estimation of funds. what kind of risk has rick identified? rick has identified a risk.
Answers: 1
question
Computers and Technology, 24.06.2019 22:00
Ican’t open these when it’s just a comment. someone pls explain why this is happening
Answers: 1
You know the right answer?
C++ PLEASE :We commonly write arithmetic expressions in infix form, that is, with each operatior pla...
Questions
question
Mathematics, 23.09.2020 18:01
Questions on the website: 13722361