Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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+*".
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago