Computers and Technology

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.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:00, abbygriffin2009
Martha is a healer, a healthcare provider, and an experienced nurse. she wants to share her daily experiences, as well as her 12 years of work knowledge, with people who may be interested in health and healing. which mode of internet communication can martha use?
Answers: 3
image
Computers and Technology, 22.06.2019 23:30, TheBurntToast
What is the digital revolution and how did it change society? what are the benefits of digital media?
Answers: 1
image
Computers and Technology, 23.06.2019 02:30, reyne36
Rafael needs to add a title row to a table that he has inserted in word. what should he do? use the alignment options. use the merge and center option for all the cells in the top row. use the merge and center option on the first two cells in the top row. none of the above
Answers: 3
image
Computers and Technology, 24.06.2019 01:30, kevin72836
Hazel has just finished adding pictures to her holiday newsletter. she decides to crop an image. what is cropping an image?
Answers: 1
Do you know the correct answer?
C++ PLEASE :We commonly write arithmetic expressions in infix form, that is, with each operatior pla...

Questions in other subjects:

Konu
Mathematics, 21.10.2020 17:01
Konu
Mathematics, 21.10.2020 17:01