Program #8: Infix to Postfix (and Evaluation)


5/5 - (2 votes)

For this assignment, I want you to create and submit a file which
can be used to convert single digit infix expressions to their postfix equivalents, and then
evaluate the postfix expressions. It should receive the infix expressions from stdin and send
output to stdout. An example run of your program might be:
java Infix2Postfix < SampleInputFile ResultingOutputFile
Your program should also make use of the,, and programs that you created for Assignments #5, #6 and #7.
Here are a few things to note:
1. You will be provided with two files i.e. a sample input file (input), and its corresponding output file (output)that you can compare with your own output.
2. The sample input file provided contains a single infix expression per line.
3. Structure your output so that it displays the infix expression on a line, the postfix
expression on the next line, the result on the next line, followed by a blank line. Do
not put spaces in between operators or operands; for example:
4. Producing the output above will require a slight modification of your file
such that it does not print spaces in between list items.
5. Your file will require the,, and
files to exist within the same folder.6. Evaluations must be precise (i.e., no integer division). Think about what this means
in terms of your evaluation stack.
7. You might want to change the MAX SIZE of your list such that it can support an entire
line of input from stdin and not just 50 items. I suggest changing the MAX SIZE to
This is a large and relatively complicated program so I suggest a few things
• Start this project as soon as possible. Procrastination, and NOT program complexity, will be your worst enemy in this project.
• Break the project into smaller parts or units in both design, and the order in which
you implement it. For example, you could:
{ Start with making sure that your code can read a line from stdin, and reproduce
that line in stdout.
{ Follow up by using I/O redirection such that your program can read the input
file line by line, and reproduce that line in the output.
{ Write functions that will allow you to successfully evaluate a postfix expression
using a stack (the same way we did in class and in your midterm). You can test
this part using another input file that you can create for yourself using either your
own postfix expressions, or the postfix expressions from the provided output file.
{ Implement an algorithm that would convert an infix expression to a postfix expression (We went over the pseudocode for such an algorithm in class, and it
should be in your notes).
Remember this is a suggestion. If you feel like you have a better way of tackling this
problem within its restrictions, please feel free to use that way.
• Note that 2^3^2 = 512.
• Feel free to compare your output to mine using the command prompt. For example,
once completed, the three commands below should NOT produce any output.
java Infix2Postfix < input myoutput
diff output myOutput
java Infix2Postfix < input myoutput
fc output myOutput

PlaceholderProgram #8: Infix to Postfix (and Evaluation)
Open chat
Need help?
Can we help?