Homework #2
Question
one (100 points)
In
ADA, you are to build a prefix to postfix converter. You will be given an input file with expressions in prefix
notation and you will need to build an expression tree for each expression. You will then output each equivalent postfix
expression to a file.
Things
you need to look up/brush up on:
·
Trees
·
Tree
Traversal
·
Input/Output
to Files
·
Parsing
Input
Work
on the problem in steps. While this is
one problem to solve, each intermediate problem is worth some points. The file input/output working, constructing
the tree, etc.
Assume
that the file will consist of one or more lines, with each line containing a
prefix expression. Each component of
the expression will be separated by a space, for easier parsing. Example:
* 7 8
* 78 9
+ - 6 5 34
Valid
operators include addition (+), subtraction (-), multiplication (*), and
division (/). Your output file should
be constructed with the same format.
For simplicity, you may hardcode the names of your input and output
files within your program (but do indicate the names of the files in the header
comments of your program for grading purposes).
We
will discuss the basic algorithms for tree traversal in class, and will discuss
how to create such a structure.
Name
your program HW2.adb and submit using the electronic submission program:
submit_cse305 HW2.adb
If
you are using more than one file, make sure you zip them and call the zip
HW2.zip. If there are special
instructions, please include a file named README. Please follow the naming conventions. Failure to do so will cause your assignment to not be graded.