Professional Documents
Culture Documents
Introduction
It is a non-trivial task for a computer system to evaluate complex expressions in infix
form, such as 12+34*(10+5)–3*4, because the precedence rule would require certain
operations to be performed before others (which is why prefix and postfix expressions
are easier to evaluate). A simple method to resolve this complexity is to require all
operations to be fully parenthesized. That is, every pair of operands and their operator
must be enclosed by parentheses. The previous expression would be written as
((12+(34*(10+5)))–(3*4)).
Task
You will create a program to evaluate fully-parenthesized expressions and store the
results in variables, where those variables may be used in subsequent expressions.
The expressions will be read from an input file and once all of the expressions have
been evaluated the program will print a table that shows the final value of each variable.
Technical Details
Input format
The input to your program will be a file named expressions.txt that consists of an
unknown number of assignment statements, each in one of two possible forms:
variable = integer
variable : expression
How to evaluate
How do you evaluate a fully-parenthesized expression? Using several stacks! Your
program must scan the expression from left to right and process each character from
the expression as follows:
At the end of the expression, the enclosure stack and the operator stack must be empty
and the operand stack must contain a single value, which the value of the expression.
Otherwise, the expression is invalid.
Sample Output
L:(A-X)) is invalid
J:([X-(A/W])*L is invalid
W:A+X is invalid
variable value
----------------
L 1400
W 10
A 50
X 100
J 8550
Submission
Your submission must consist of five files:
1. StackADT.h (as provided in class, without any changes)
2. LinkedStack.h and/or ArrayStack.h (as provided in class; no changes)
3. ExpressionEvaluator.cpp (main program)
The final date to submit your program will be Friday, Nov 17, 2023 at 11:59pm. The
name of your zip file must follow the following format: P2_4005_nnnnnnnn_231.zip, where
nnnnnnnnn should be replaced with your student id number. There will be a 20 point
penalty for every day that the project is late.
Academic Integrity
Do NOT share your code! You may discuss design/implementation
strategies, but if projects are too similar for it to be a coincidence, all parties
involved will receive a grade of 0. Don’t cheat yourself out of a learning
experience; seek help if you need it.
Final comments
The specifications of a project are the first, and arguably the most important, part of a
software development project. Therefore, it’s crucial that you read these specifications
thoroughly so that you understand what is being asked of you. These are skills that
you will need to succeed in your professional career, so it’s imperative that you start
applying and improving them now. If your program runs successfully, but does not
adhere to the specifications, it is of no use. Before you submit your project, review
these specifications one last time and make sure you meet all of the requirements that
have been imposed.