Question: Implement InfixExpression class that is used to create and instantiate expressions in infix notations as objects. This class has one string attribute expression which holds

Implement InfixExpression class that is used to create and instantiate expressions in infix notations as objects. This class has one string attribute expression which holds the value of the expression. For example, "A+B" is a possible value of such expression. Make sure to define that attribute as a private attribute and add setter and getter for it using decorators. You are also required to add the following instance methods to your class:
update_expression(self, operator, expression) where operator is a character and expression is a string which represents another expression. The method should not return anything, rather it should update the expression of the InfixExpression object. Precisely, it should set the expression of the InfixExpression object to
1
be (le)op(re) where le is the expression of the object, op is operator, and re is expression.
Example
Let e be an InfixExpression whose expression has the value "A+B*C". Then
e.update_expression("-","D") updates the expression of the infix expression e to be "(A+B**C)-(D)"; and
e.update_expression("^","D/(E-F)") updates the expression of the infix expression e to be "(A+B**C)???(DE-F).
convert_to_postfix(self) that uses the class Stack to return a string which is the expression in postfix notation. You have to consider only the following five arithmetic operators: ^, C","A (B+C)"; respectively. Then
e1.convert_to_postfix ()="ABC*+";
e2. convert_to_postfix ()="AB*C+"; and
e3.convert_to_postfix ()="ABC+*".
 Implement InfixExpression class that is used to create and instantiate expressions

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!