Website Summary Files Commits Branches @commit @diff @stats
path: root / Polymorphism / MathExpression / Operation.hpp
diff options
context:
space:
mode:
Commitd2422da2c1b2fcf75a3212eb36e94a718a39c0a5 (patch)
Author
 Angeld55 <achi_d@abv.bg>
2019-09-20 16:02:36 +0300
Committer
 GitHub <noreply@github.com>
2019-09-20 16:02:36 +0300
Files153acaf6a9084a50972b7542d737290219f72cf3 /Polymorphism/MathExpression/Operation.hpp
Object-oriented_programming_FMI-d2422da2c1b2fcf75a3212eb36e94a718a39c0a5.tar
Object-oriented_programming_FMI-d2422da2c1b2fcf75a3212eb36e94a718a39c0a5.tar.gz
Object-oriented_programming_FMI-d2422da2c1b2fcf75a3212eb36e94a718a39c0a5.zip
Parent5e5abf297fcac67a3eb59db0a520eb6e63ffa531 (diff)
Add files via upload
1 files changed, 46 insertions, 0 deletions
-rw-r--r--Polymorphism/MathExpression/Operation.hpp46
diff --git a/Polymorphism/MathExpression/Operation.hpp b/Polymorphism/MathExpression/Operation.hpp
new file mode 100644
index 0000000..cfa9534
--- /dev/null
+++ b/Polymorphism/MathExpression/Operation.hpp
@@ -0,0 +1,46 @@
+class Operation : public Expression
+{
+
+public:
+ Expression* left;
+ char op;
+ Expression* right;
+ Operation(Expression* left, char ch, Expression* right)
+ {
+
+ this->left = left;
+ op = ch;
+ this->right = right;
+ type = 2;
+
+ }
+ void Print()
+ {
+ std::cout << '(';
+ left->Print();
+ std::cout << op;
+ right->Print();
+ std::cout << ')';
+ }
+ int Evaluate()
+ {
+ int result = left->Evaluate();
+ int value2 = right->Evaluate();
+
+ if (op == '+')
+ result += value2;
+ else if (op == '*')
+ result *= value2;
+ else
+ return 0; //Invalid operation
+ return result;
+ }
+ ~Operation()
+ {
+
+ delete left;
+ delete right;
+ op = '\0';
+ }
+
+}; \ No newline at end of file