CSC 172
Write a desk calculator program. It should present a nice user interface for infix expressions. It should use two stacks to parse a line of input, check for matching parentheses, and evaluate the expression. You never need to produce the postfix representation explicitly - instead you can use the two stacks to convert and evaluate as you go... The conversion uses a stack of operators, the evaluation uses a stack of operands. You may find a use for a queue in this assignment, possibly to hold the tokens you extract from the input stream. Thus at least a stack class is indicated and possibly a queue class.
Your calculator should use float (or double) as its internal representation, and should support the operations +, *, binary -, and /. If you want to add unary minus that would be interesting. You can assume left to right (1 + 2 * 3= 9 ) or right to left precedence (1 + 2 * 3= 7 ) if you don't want to implement the ``normal'' precedence relations for unparenthesized infix expressions. Your calculator should inform its user what precedence is being used, however.
As an illustration of the two stacks working together, here is a trace for the expression (11 - 7)*6 (stacks grow towards right).
Operator Operand Stack Stack ( ( 11 (- 11 (- 11 7 ( 4 4 * 4 * 4 6 24
Another approach to this problemis to make an infix-to-postfix translator and a postfix evaluator, and to send the output from the first into the second. One nice aspect to that approach is the intermediate explicit postfix form.
Turn in a directory with your code, a README file that is well-written and spell-checked file that tells the contents of the various files in the directory. It should document your approach, the functionality of the various subroutines, the semantics of the classes, and so forth, so that the code can be understood. Also the README should provide a user's manual: how to run the code. If you have sample data files, script() transcripts of sessions showing the code working, tell about them. Do not include .o, outdated versions (.bak or ``tilde'' files) or binary executable files in the directory.