aboutsummaryrefslogtreecommitdiff
path: root/tree.h
blob: b112dcbcab424c861250f028cf54b7bbff424806 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <vector>
#include <string>
#include <sstream>
#include <math.h>

using namespace std;

enum NodeType 
{
	OPERAND_NODE,
	OPERATOR_NODE,
};

class Node
{
	public:
		Node();
		double solve();

		template <class T>
		double castSolve(Node*);
		
		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.";
	}
};