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 13:10
Calculating the "total price" of an item is tedious, so implement a get_item_cost method that just returns the quantity times the price for an item. by the way, the technical term for this kind of instance method is an accessor method, but you'll hear developers calling them getters because they always start with "get" and they get some value from instance attributes. in order to make the items sortable by their total total price, we need to customize our class. search the lectures slides for "magic" to see how to do this. see section 9.8 for an additional reference. the receipt class: this will be the class that defines our receipt type. obviously, a receipt will consist of the items on the receipt. this is called the composition design pattern. and it is very powerful. instance attributes: customer_name : it is very important to always know everything you can about your customers for "analytics", so you will keep track of a string customer name in objects of type receipt. date : the legal team has required that you keep track of the dates that purchases happen for "legal reasons", so you will also keep track of the string date in objects of type receipt. cart_items : this will be a list of the items in the cart and hence end up on the receipt. methods: 1. create a default constructor that can take a customer name as an argument, but if it gets no customer name, it will just put "real human" for the customer_name attribute. it should also accept a date argument, but will just use the value "today" for the date instance attribute if no date is given. the parameters should be named the same as the instance attributes to keep things simple. 2. add_item : self-descriptive. takes a parameter which we hope beyond hope is of type itemtopurchase and adds it to the cart_items. returns none. 3. print_receipt : takes a single parameter isevil, with default value true. returns a total cost of all the items on the receipt (remember to factor in the quantity). prints the receipt based on the following specification: for example, if isevil is true, and customer_name and date are the default values: welcome to evilmart, real human today have an evil day! otherwise, it should print: welcome to goodgo, real human today have an good day! then the receipt should be printed in sorted order like we discussed earlier, but whether or not it starts with the highest cost (think reverse), depends on the value of isevil. if it is evil, then the lowest cost items should print first, but if it is good, then it will print the highest cost items first. (cost meaning price*quantity). remember to return the total cost regardless! your main() function: the main flow of control of your program should go in a main() function or the program will fail all the unit tests. get the name of the customer with the prompt: enter customer name: get the date with the prompt: enter today's date then, ask the question: are you evil? your program should consider the following as true: yeah yup let's face it: yes hint: what do these strings all have in common? your program should consider all the following as false: no nah perhaps but i'm leaning no (just be glad you don't have to handle "yeah no.") okay enough horsing around. (get it? aggies? ! horsing! ) next, in the main() function, you will have to create a receipt object and start adding things into it using an input-while loop. the loop will prompt the user for the item name exactly as in the previous zylab (9.11). but unlike the previous zylab, the loop will terminate only if an empty string is entered for the item name. then, the price and the quantity will be prompted for exactly as in the previous zylab. create the itemtopurchase objects in the same manner as the previous zylab, but don't forget to add them to the receipt using your add_item instance method. then, the items on the receipt should be printed with the same formatting as in the previous zylab, of course with either "good" or "evil" ordering. however, on the last line, the total should be printed as follows: where 10 is replaced by the actual total. sample run here is what a sample run of the final program should look like: enter customer name: nate enter today's date: 12/20/2019 are you evil? bwahahahaha yes enter the item name: bottled student tears enter the item price: 2 enter the item quantity: 299 enter the item name: salt enter the item price: 2 enter the item quantity: 1 enter the item name: welcome to evilmart, nate 12/20/2019 have an evil day! salt 1 @ $2 = $2 bottled student tears 299 @ $2 = $598 total: $600
Answers: 1
question
Computers and Technology, 23.06.2019 20:30
What are some settings you can control when formatting columns?
Answers: 1
question
Computers and Technology, 24.06.2019 13:50
Write a program that performs a simple n-body simulation, called "jumping leprechauns." this simulation involves n leprechauns, numberd 1 to n. it maintains a gold value g_i for each leprechaun i, which begins with each leprechaun starting out with a million dollars worth of gold, that is, g_i = 1000000 for each i = 1,. in addition, the simulation also maintains, for each leprachaun,i, a place on the horizon, which is represented as a double-precision floating point number, x_i. in each iteration of the simulation, the simulation processes the leprachauns in order. processing a leprachaun i during its iteration begins by computing a new place on the horizon for i, which is determined by the assignment:
Answers: 3
question
Computers and Technology, 24.06.2019 18:00
Why is a multiview sketch drawinf different from other sketches like isometric, two point, and oblique
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, 12.12.2020 22:30
question
Mathematics, 12.12.2020 22:30
question
Mathematics, 12.12.2020 22:30
question
Business, 12.12.2020 22:30
question
History, 12.12.2020 22:30
question
Biology, 12.12.2020 22:30
question
Mathematics, 12.12.2020 22:30