Question: c++ , please if u can explain it thoroughly It'll be appreciate! Let V = {V1, V2, ..., Vn} be a set of variables that

 c++ , please if u can explain it thoroughly It'll be

appreciate! Let V = {V1, V2, ..., Vn} be a set of

variables that take values from Z. An expression is defined as follows:

v is an expression where v EV. . (oe) is an expression

c++ , please if u can explain it thoroughly It'll be appreciate!

Let V = {V1, V2, ..., Vn} be a set of variables that take values from Z. An expression is defined as follows: v is an expression where v EV. . (oe) is an expression where e is an expression, and o {-, !} is a unary operation denoting either negation or logical not. (e, o ez) is an expression where ej and e2 are expressions and o E {+,-.*./.%,<.>.> , ==, and, or} is a binary operation with the typical semantics. Consequently, an expression has a name, a value, and a type (variable, unary-op, or binary-op). Based on its type, an expression may have zero, one, or two operands who in turn are expressions. In the previous lab we defined, printed, and evaluated expressions using five arrays (see Figure 1). In this lab, we will do the same using a 1) user-defined class Expression and using 2) inheritance and overloading (polymorphism). 6 10 indices 0 2 3 types VAR VAR VAR UN 5 BIN 8 9 BIN BIN BIN BIN UN UN names II + 11 operand1 -1 -1 0 1 0 5 6 1 7. 9 operand2 - 1 -1 -1 3 2 4 2 8 - values Figure 1: Array representation of expressions. Entries at index 10 in the arrays specify expression !(-((x + 2)/(y * (-1))) > (y/2)). Problem 1: Expression class Instead of having several arrays, we will create a user-defined structure called Expression and have only one array of objects of type Expression. Structure Expression has a name, a value, a type, and two operands. The class will also have methods print, set VarValue, and computeValue. These methods do not have to take the index of the expression we are currently operating on, since that expression would be the object itself. Also, we only need to pass one array of expressions instead of several arrays (see main below). Implement the same scenario as in Lab 2's Problem 5; no need to implement constructing an expression from the user again. int main() { Expression expressions (capacity] = { {"x", VAR,-1,-1,0}, {"y", VAR,-1,-1,0}, {"z", VAR,-1,-1,0}, {"-", UN, 0,-1,0}, {"*" BIN,1,3,0}, {"+", BIN,0,2,0], {"/",BIN,5,4,0}, {"-", UN,6,-1,0}, {"/", BIN,1,2,0], {">", BIN,7,8,0}, {"!", UN,9,-1,0} }; expressions [10] .print(expressions, 11); expressions[0].setVarValue(5); expressions (1).setVarValue(5); expressions (2).setVarValue(5); int val=expressions (10].computeValue( expressions, 11); "

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!