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, 22.06.2019 23:30
In my email i got a message it says a quick message and in message details on who its from its says nicole and under nicole is [email protected] -
Answers: 1
question
Computers and Technology, 24.06.2019 17:50
You will subnet the network address 172.31.103.0/24. the network has the following requirements: Β· room-114 lan will require 27 host ip addresses Β· room-279 lan will require 25 host ip addresses Β· room-312 lan will require 14 host ip addresses Β· room-407 lan will require 8 host ip addresses how many subnets are needed in the network topology?
Answers: 2
question
Computers and Technology, 24.06.2019 18:30
In what way is your social media footprint related to your digital id
Answers: 1
question
Computers and Technology, 24.06.2019 20:20
3. write assignment statements that perform the following operations with the variables a, b, and c: a. adds 2 to a and assigns the result to b b. multiplies b times 4 and assigns the result to a c. divides a by 3.14 and assigns the result to b
Answers: 2
You know the right answer?
C++ PLEASE :We commonly write arithmetic expressions in infix form, that is, with each operatior pla...
Questions
question
Mathematics, 01.02.2021 20:00
question
Social Studies, 01.02.2021 20:00
question
Mathematics, 01.02.2021 20:00
question
Mathematics, 01.02.2021 20:00
question
Mathematics, 01.02.2021 20:00
Questions on the website: 13722367