aboutsummaryrefslogtreecommitdiff
path: root/tree.h
diff options
context:
space:
mode:
Diffstat (limited to 'tree.h')
-rw-r--r--tree.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/tree.h b/tree.h
new file mode 100644
index 0000000..48f4de1
--- /dev/null
+++ b/tree.h
@@ -0,0 +1,64 @@
+#include <vector>
+#include <string>
+#include <stdlib.h>
+
+using namespace std;
+
+enum NodeType
+{
+ OPERAND_NODE,
+ OPERATOR_NODE,
+};
+
+class Node
+{
+ public:
+ Node();
+ double solve();
+
+ Node *leftChild;
+ Node *rightChild;
+
+ NodeType type;
+};
+
+class OperatorNode: public Node
+{
+ public:
+ OperatorNode();
+ double solve();
+ char function;
+};
+
+
+class OperandNode: public Node
+{
+ public:
+ OperandNode();
+ double solve();
+ double value;
+};
+
+class Tree
+{
+ public:
+ Tree();
+
+ Node *root;
+
+ Node* addOperand(Node**, double);
+ Node* addOperator(Node**, char);
+
+ string print(string);
+
+ private:
+ vector<Node*> *nodeCollection;
+};
+
+class divide_exception: public exception
+{
+ virtual const char* what() const throw()
+ {
+ return "A divison through zero had to be prevented by the parser - check your input term.";
+ }
+}; \ No newline at end of file