CSC 304 Assignment #2 solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (4 votes)

Design a python class Expression with two fields _infix and _postfix that contains a constructor
__init__(self, input, direction) and three methods
1. in_to_post()
2. post_to_in()
3. evaluate()
The first method transforms the local infix expression to postfix, stores it in _postfix and returns it from the
method. The second method is the inverse: it transforms the local postfix expression to infix, stores it in
_infix, and returns it as a string. The method evaluate() returns the value of the expression.
Your main() should display a prompt to the user, give him/her the opportunity to enter a string in either
notation (hence the two different directions in the constructor) to be transformed to the other, and evaluate
the result. After entering the expression, the user should be prompted for direction which should be 0 if
user enters an infix expression, and 1 if user enters a postfix expression. You may use the ArrayStack class
from lecture 6 to perform your conversions and evaluations. Your stack class (ArrayStack, or otherwise) should
be a private field of your Expression class.
If your program has any fancy features, such as allowing multiple-digit numbers, checking for illegal
characters in the input, adding some extra operators, or others, please make that clear in a comment at the
beginning of your program. Also, when you display the menu of options to the user, make it clear how they
should enter the expressions (i.e. leave spaces around operators etc..)
Don’t forget that the mark includes:
– a working program
– a well-tested program
– and any extras you add!