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 02:00
Aisha has finished working on a word processing document that contains 15 pages. she has added some special elements in the first three pages, page 9 and 10, and page 15 from the document. she wants to print only these pages to see how they look. which option is the correct way to represent (in the print dialog box) the pages that aisha wants to print?
Answers: 1
question
Computers and Technology, 22.06.2019 06:00
In outlook how can cherie look at the details of an event that appears on the month view of her calendar? check all that apply. by switching to the detail view by switching to the week view by switching to the day view by right-clicking on the event by double-clicking on the event by highlighting the event
Answers: 2
question
Computers and Technology, 23.06.2019 04:00
In a word processing program, such as microsoft word, which feature to you choose the desired picture enhancement?
Answers: 2
question
Computers and Technology, 23.06.2019 18:50
What is transmission control protocol/internet protocol (tcp/ip)? software that prevents direct communication between a sending and receiving computer and is used to monitor packets for security reasons a standard that specifies the format of data as well as the rules to be followed during transmission a simple network protocol that allows the transfer of files between two computers on the internet a standard internet protocol that provides the technical foundation for the public internet as well as for large numbers of private networks
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, 12.10.2020 17:01
question
Mathematics, 12.10.2020 17:01
question
Mathematics, 12.10.2020 17:01
question
Social Studies, 12.10.2020 17:01
question
Mathematics, 12.10.2020 17:01
Questions on the website: 13722363