#ifndef NODE #define NODE #include #include /** *A Node represents any item which can be part of an expression. *This includes constants, and binary operators. Node is a abstract base *class, while both constant and binary operators are subclasses.The binary *operators will become internal nodes, as will the unary operators, *while the constants will be external nodes. * * Written by Jessica Smith from code created by rcd. */ class Node { public: virtual ~Node(){} /* *Evaluates the node's value */ virtual double evaluate () const = 0; /** *Prints out the node's value */ virtual void print (ostream & out) const = 0; /** *Returns a copy of the node */ virtual Node * copy () const = 0; /** *Returns the precedence of the node */ virtual int precedence()const=0; /** *Sets left children */ virtual char parenSymbol() { return(' '); }//for parenthesis virtual void Left(Node * lhNode){}; /** *Returns the description of the node */ /** *Sets Right children */ virtual void Right(Node * rhNode){}; virtual string description() const=0; virtual void changePrecedence(int precedence) { } virtual Node* takeDerivative(string & key) { return (0); } virtual void postAlert(bool statement){} virtual bool getAlert() { return false; } virtual bool isVariable() { return false; } }; /** *The constant class is a subclass of node which allows constants to be *created as nodes */ class Constant : public Node { public: /** *Makes a constant node from the given value */ Constant (double value); /** *Virtual destructor for COnstnat */ virtual ~Constant(); /** *Evaluates value of the constant node, returns myValue */ virtual double evaluate () const; /** *Prints out the value of the constant node */ virtual void print (ostream & out) const; /** *Copies the node */ virtual Node * copy () const; /** *Returns the precedebce of the node */ virtual int precedence()const; /* *Returns the value of the int in string form */ virtual string description()const;//returns double value /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); private: double myValue; int myPrecedence; }; class Paren : public Node { public: /** *Makes a Paren Node */ Paren (const char & parenthesis,const int & precedence); virtual ~Paren(); /** *Evaluates value of the paren node */ virtual double evaluate () const; /** *Describe Paren */ virtual string description() const; /** *Prints out the value of the Paren node */ virtual void print (ostream & out) const; /** *Copies the node */ virtual Node * copy () const; /** *Returns the precedebce of the node */ virtual int precedence()const; /** *Returns the parentheis symbol(left or right) */ virtual char parenSymbol(); private: char myParenthesis; int myPrecedence; }; class Equals : public Node { public: /** *Makes a Equal node */ Equals (); /** *Destructor */ virtual ~Equals(); /** *Prints out the equal sign */ virtual void print (ostream & out) const; virtual string description()const;//returns int value virtual double evaluate () const; /** *Copies the node */ virtual Node * copy () const; /** *Returns the precedebce of the node */ virtual int precedence()const; private: int myPrecedence; }; class Variable: public Node { public: /** *Makes a Variable node from the given value */ Variable(string name); Variable(string name, double value); Variable(string name, double value, int precedence); /* *Destructor */ virtual ~Variable(); /** *Prints out the value of the constant node */ virtual string description()const; virtual void print (ostream & out) const; /** *Evaluate varaible */ virtual double evaluate () const; /** *Copies the node */ virtual Node * copy () const; /** *Returns the precedence of the node */ virtual int precedence()const; /** *Sets left children */ /** *Knows derivatives to take */ virtual Node* takeDerivative(string & key); virtual void Left(Node * lhNode); virtual void changePrecedence(int precedence); virtual void postAlert(bool statement); virtual bool getAlert(); virtual bool isVariable(); private: string myName; double myValue; int myPrecedence; Node* myLHS; bool myAlert; //used if only want to evaluate a vairable }; class Comma : public Node { public: /** *Makes a Comma node */ Comma (); /** *Destructor */ virtual ~Comma(); /** *Prints out the comma sign */ virtual void print (ostream & out) const; virtual string description()const;//returns int value virtual double evaluate () const; /** *Copies the node */ virtual Node * copy () const; /** *Returns the precedebce of the node */ virtual int precedence()const; private: int myPrecedence; }; # endif NODE