LAB 4— Postfix expressions evaluation, Due Friday February 29th at 23:59.

Remark: late submissions wont be marked.

Problem Statement.

Implement the postfix expressions evaluation algorithm in your text book (page 349).
 

Input file:

The program has one input file called “postfix.txt” that contains a postfix expression in each line.  Below is a sample:

23 45 +
9 6 12 + *
5 7 / 10 -
25
56 - 45

The operands in the postfix expressions are positive integers and the operators are also binary operators: +, -, *, and /. The division operator is integer operator, for instance 5 / 7 = 0. The operand and operators are separated by space. You can assume that there is no invalid characters in the input expression.

Output:

Your program should evaluate each postfix expression and print its value on a new line. If an expression is not a valid postfix expression the program must output “Invalid postfix expression” . The output of the above input file should be:

68
162
-10
25
Invalid postfix expression

Implementation.

You need to use a stack class for this program. You can use the one that you implemented in Lab3. For Java programmers: You must name your main class  (the class with the main method) postfixEval.java.

Standards (very important): your program must follow the exact output and input specifications mentioned above. The name and the format of the input file, the format of the output, and the name of the main class must follow the above mentioned rules . Failing to comply to the standards will result in up to 50% penalty.

Style: part of the grade is for having proper style which includes proper indenting and having enough comments.

Submission: zip all your source files (DO NOT SUBMIT THE .class or .exe files) and submit it through submission server submit.cs.sfu.ca. The submission server only accepts the zipped files. You can zip your assignment files using the winzip program or the zip, gzip linux command, DO NOT SUBMIT RAR FILES. Include your name and student number in your source file that includes the main function.

Remark: there will be four submission groups for each lab assignment make sure you submit to the group that you belong to (if you are registered in the first lab submit to the first group, and so on) otherwise there will be a 50% penalty.

Implementation Language: The programming problems in assignments, can be written in either JAVA or C++. It’s not necessary to learn JAVA for those who know only C++ and to learn C++ for those who know only JAVA.