#ifndef BFUNCNODE #define BFUNCNODE #include #include #include "node.h" /** *Makes Binary Operator which is a subclass of node. This class is *the superclass for all of the binary functions. */ class BinaryFunction : public Node { public: /** *Makes a BinaryFunction with no nodes attached underneath */ BinaryFunction(); /** *Make a BinaryFunction Node with lhs assigned as left child, and rhs as *right root */ BinaryFunction (Node * lhs, Node * rhs); /** *Destroys the BinaryFunction when out of scope */ virtual ~BinaryFunction (); /** *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; }; class Log : public BinaryFunction { public: /** *Default Log constructor */ Log(); /** *Sets Log with left and right leaves */ Log (Node * lhs, Node * rhs); /** *Evaluates the log of the leaves */ virtual double evaluate () const; /** *Makes a copy of the node */ virtual Node * copy () const; protected: virtual string description () const; }; class Derivative : public BinaryFunction { public: /** *Default Derivative constructor */ Derivative(); /** *Sets Derivative with left and right leaves */ Derivative (Node * lhs, Node * rhs); /** *Evaluates the Derivative of the leaves */ virtual double evaluate () const; /** *Makes a copy of the node */ virtual Node * copy () const; Node * takeDerivative(string & key); protected: virtual string description () const; }; class Function : public BinaryFunction { public: /** *Default Function constructor */ Function(); /** *Sets Function with left and right leaves */ Function (Node * lhs, Node * rhs); /** *Evaluates the Function of the leaves */ virtual double evaluate () const; /** *Makes a copy of the node */ virtual Node * copy () const; Node * specialEvaluation(string & key, double & value); protected: virtual string description () const; }; #endif BFUNCNODE