#ifndef UNARYNODE #define UNARYNODE #include #include /** *A UNARY Node is a subclass of node. That has only one leaf. * * Written by Jessica Smith from code created by rcd. */ class UnaryOperator : public Node { public: /** *Makes a UnaryOperator with no nodes attached underneath */ UnaryOperator(); /** *Make a UnaryOperator Node with lhs assigned as left child */ UnaryOperator (Node * lhs); /* *Destroys the UnaryOperator when out of scope */ virtual ~UnaryOperator (); /** *Allows the UnaryOperator to be printed out */ virtual double evaluate()const =0; virtual void print (ostream & out) const; /** *Returns the precedence of the node */ virtual int precedence()const; /** *Sets left children */ virtual void Left(Node * lhNode); protected: // accessible to derived classes virtual string description () const = 0; /** *Created a node only accesible to subclasses and a myPrecedence only *accesible to subclasses */ Node* myLHS; int myPrecedence; }; class Negative : public UnaryOperator { public: /** * Allows a Negative node to be created with no nodes attached */ Negative(); /** *Creates a Negative node with two nodes, lhs and rhs attached */ Negative (Node * lhs); /** *Evaluates the Negative node */ virtual double evaluate () const; /** *Copies a Negative node */ virtual Node * copy () const; /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); protected: virtual string description () const; }; class Factorial : public UnaryOperator { public: /** * Allows a Factorial node to be created with no nodes attached */ Factorial(); /** *Creates a Factorial node with two nodes, lhs and rhs attached */ Factorial (Node * lhs); /** *Evaluates the Factorial node */ virtual double evaluate () const; /** *Copies a Factorial node */ virtual Node * copy () const; protected: virtual string description () const; }; class Sqrt : public UnaryOperator { public: /** * Allows a Sqrt node to be created with no nodes attached */ Sqrt(); /** *Creates a Sqrt node with two nodes, lhs and rhs attached */ Sqrt (Node * lhs); /** *Evaluates the Sqrt node */ virtual double evaluate () const; /** *Copies a Sqrt node */ virtual Node * copy () const; /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); protected: virtual string description () const; }; class Abs : public UnaryOperator { public: /** * Allows a Abs node to be created with no nodes attached */ Abs(); /** *Creates a Abs node with two nodes, lhs and rhs attached */ Abs (Node * lhs); /** *Evaluates the Abs node */ virtual double evaluate () const; /** *Copies a Abs node */ virtual Node * copy () const; protected: virtual string description () const; }; class Sin : public UnaryOperator { public: /** * Allows a Sin node to be created with no nodes attached */ Sin(); /** *Creates a Sin node with one node */ Sin (Node * lhs); /** *Evaluates the Sin node */ virtual double evaluate () const; /** *Copies a Sin node */ virtual Node * copy () const; /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); protected: virtual string description () const; }; class Cos : public UnaryOperator { public: /** * Allows a Cos node to be created with no nodes attached */ Cos(); /** *Creates a Cos node with one node */ Cos (Node * lhs); /** *Evaluates the Cos node */ virtual double evaluate () const; /** *Copies a Cos node */ virtual Node * copy () const; /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); protected: virtual string description () const; }; class Tan : public UnaryOperator { public: /** * Allows a Tan node to be created with no nodes attached */ Tan(); /** *Creates a Tan node with one node */ Tan (Node * lhs); /** *Evaluates the Tan node */ virtual double evaluate () const; /** *Copies a Tan node */ virtual Node * copy () const; /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); protected: virtual string description () const; }; class LN : public UnaryOperator { public: /** * Allows a LN node to be created with no nodes attached */ LN(); /** *Creates a LN node with one node */ LN (Node * lhs); /** *Evaluates the LN node */ virtual double evaluate () const; /** *Copies a LN node */ virtual Node * copy () const; /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); protected: virtual string description () const; }; class Exp : public UnaryOperator { public: /** * Allows a Exp node to be created with no nodes attached */ Exp(); /** *Creates a Exp node with one node */ Exp (Node * lhs); /** *Evaluates the Exp node */ virtual double evaluate () const; /** *Copies a Exp node */ virtual Node * copy () const; /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); protected: virtual string description () const; }; #endif UNARYNODE