Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a pseudocode algorithm for a calculator app that uses postfir notation. No

ID: 666338 • Letter: W

Question

Write a pseudocode algorithm for a calculator app that uses postfir notation. Normally, we write arithmetic expessions like this: ((34 12) × (8 +2)) × 7 This is called infir notation. We use the brackets to indicate the order of operations As we saw in lecture, we don't need brackets at all, if we use postfix notation. Here's the same expression, using postfix notation. 312+82+×7× Looks weird, but here's how to read it (left to right): 312+82+×7× To design an algorithm for this, you will need to make use of the Stack ADT operations (though you don't need to implement the operations for this question). Other ideas that you should use: . Assume that the user's input will be a postfix expression (you don't need to worry about checking the cor rectness of the expression) with all elements in the expres sn separated by at least one space. This will simplify the parsing of the input. In other words, suppose the " is a visible space character, you can expect 3.12,Tw8.2+*.7, and you don't have to worry about expressions like: 312-82_17* 2. Assume that all expressions are made up of either numbers (float or int), and arithmetic operators, and nothing else. You don't need to handle cases that handle the wrong kinds of inputs 3. Assume you can read an element in an expression, and ask what kind of thing it is. For example: read thing if (thing is a number) then // do something else if (thing is a') then // do something else end Assume you don't have to handle any errors,1

Explanation / Answer

init(Stack S) //postfix expression evaluation requires stack so initialise it t = readToken(); // Read Token while(t) { if ( t is Operand ) Push ( t ) Onto Stack S. if ( t is Operator ) { Operand2 = Pop(Stack S); Operand2 = Pop(Stack S); Evaluate (Operand1,Operand2,Operator t); //if addition then it will be //Evaluate=(Operand1+Operand2) } t = readNextToken(); // read next token and continue }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote