+1(316)4441378

+44-141-628-6690

Postfix Calculator

Postfix is an expression in which the operands are placed before their operators. There are no precedence rules, no parentheses needed. For example, 11 9 – is equal to 11 – 9 in the infix notation. It’s much easier to calculate postfix expression by using the stack data structure.

For this assignment you will be using your own implementation of the generic StackClass from the in-class exercise (fill in all the methods in the attached StackClass.java template). Your calculator program should support float numbers and the following operators: + – * / ^ (all floating point operators).

Your program should have a method that accepts a string of operators and operands separated by spaces (no parentheses). Another function will process a file containing a number of expressions and invoke the calculation method for each line. Your program should should print the final result or output an error if the input is invalid. See below for more details on the input and expected output.

Hints:

    There should be exactly one element in the stack, i.e., the result of the expression.
    ^ operator will not work on floating point numbers, so you may want to import the math library.
    If you have an operator but not sufficient operands on the stack, the input expression is invalid. If your stack ends up with more than 1 operand (but no operators) on the stack, the input expression is also invalid.
    You may import external libraries for file related operations
    The algorithm is given in the following pseudocode:

                        for each char c in the string:

                                if c is operand:

                                        stack.push(c)

                                else if c is operator:

                                        pop operands to x, y

                                        result = x (oper) y

                                        stack.push(result)

Input:

You will read from a file input. Each expression will appear on a line by itself. There will be no empty lines. Operators and operands will be separated by whitespaces. Assume all operators are binary to make parsing easy.

Output:

You are to print the calulation with the expression and the result separated by an equal sign as each expression is evaluated. For example, after evaluating the expression “11 9 -“, your program will print “11 9 – = 2”. If the input expression is invalid, print =ERR=.
Also dont use complicated code

 

You can place an order similar to this with us. You are assured of an authentic custom paper delivered within the given deadline besides our 24/7 customer support all through.

 

Latest completed orders:

# topic title discipline academic level pages delivered
6
Writer's choice
Business
University
2
1 hour 32 min
7
Wise Approach to
Philosophy
College
2
2 hours 19 min
8
1980's and 1990
History
College
3
2 hours 20 min
9
pick the best topic
Finance
School
2
2 hours 27 min
10
finance for leisure
Finance
University
12
2 hours 36 min
[order_calculator]