#ifndef BINARYNODE #define BINARYNODE #include #include /** *Makes Binary Operator which is a subclass of node. This class is *the superclass for all of the binary functions. */ class BinaryOperator : public Node { public: /** *Makes a BinaryOperator with no nodes attached underneath */ BinaryOperator(); /** *Make a BinaryOperator Node with lhs assigned as left child, and rhs as *right root */ BinaryOperator (Node * lhs, Node * rhs); /** *Make a BinaryOperator Node with lhs assigned as left child, and rhs as *right root and myprecende = precence */ BinaryOperator (Node * lhs, Node * rhs,int precedence); /** *Destroys the BinaryOperator when out of scope */ virtual ~BinaryOperator (); /** *Allows the binary operator to be printed out */ virtual void print (ostream & out) const; /** *Virutal evaluate must be defined in subclasses */ virtual double evaluate()const =0; /** *Returns the precedence of the node */ virtual int precedence()const; /** *Sets left children */ virtual void Left(Node * lhNode); /** *Sets Right children */ virtual void Right(Node * rhNode); protected: // accessible to derived classes virtual string description () const = 0; /** *Created two nodes only accesible to subclasses and a myPrecende only *accesible to subclasses */ Node* myLHS; Node* myRHS; int myPrecedence; }; /** *Create a subclass plus for addition */ // define a subclass of Operator for each of +, -, *, /,%,^ class Plus : public BinaryOperator { public: /** * Allows a plus node to be created with no nodes attached */ Plus(); /** *Creates a plus node with two nodes, lhs and rhs attached */ Plus (Node * lhs, Node * rhs); /** *Evaluates the plus node */ virtual double evaluate () const; /** *Copies a plus node */ virtual Node * copy () const; /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); protected: virtual string description () const; }; /** *The minus class is a subclass of binary operators that allows *for subtraction */ class Minus : public BinaryOperator { public: /** *Creates a minus node with no children */ Minus(); /** *Creates a minus node with children lhs and rhs */ Minus (Node * lhs, Node * rhs); /** *Evaluates the rhs minus the lhs */ virtual double evaluate () const; /** *Copies the minus node */ virtual Node * copy () const; /** *Creates a description of the minus sign */ /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); protected: virtual string description () const; }; /** *Create a class times that is a subclass of node */ class Times : public BinaryOperator { public: /** *Creates default times constructor */ Times(); /** *Times constructor with leaves given */ Times (Node * lhs, Node * rhs); /** *Function to evaluate what times node evaluates to */ virtual double evaluate () const; /** *Creates a copy of the node */ virtual Node * copy () const; /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); protected: virtual string description () const; }; class Divide : public BinaryOperator { public: /** *Default division operator */ Divide(); /** *Sets leaves of division node */ Divide (Node * lhs, Node * rhs); /** *Evaluates division node */ virtual double evaluate () const; /** *Creates copy of node */ virtual Node * copy () const; /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); protected: virtual string description () const; }; class Mod : public BinaryOperator { public: /** *Default Mod constructor */ Mod(); /** *Sets mod with left and right leaves */ Mod (Node * lhs, Node * rhs); /** *Evaluates the Mod of the leaves */ virtual double evaluate () const; /** *Makes a copy of the node */ virtual Node * copy () const; protected: virtual string description () const; }; class Pow : public BinaryOperator { public: /** *Default Pow constructor */ Pow(); /** *Sets pow with left and right leaves */ Pow (Node * lhs, Node * rhs); /** *Evaluates the Power of the leaves */ virtual double evaluate () const; /** *Makes a copy of the node */ virtual Node * copy () const; /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); protected: virtual string description () const; }; #endif BINARYNODE