#include "itemtype.h" // typedef for ItemType #ifndef NULL // If NULL is not yet defined #define NULL 0 // define it #endif // The bool's that are returned by the methods take value 1 if the // method succeeds and 0 otherwise (if there is overflow, underflow, etc.) struct Monomial { int degree; float coeff; Monomial * next; Monomial(); Monomial(int newdegree, float newcoeff, Monomial * newnext); }; class Polynomial { public: // Creates a zero polynomial Polynomial(); // Frees up memory ~Polynomial(); // Sets the polynomial to 0 bool Init(); // Tests if the polynomial is 0 bool IsZero() const; // Adds the monomial specified to the current polynomial bool AddMonomial(int degree, float coeff); // Sets the current polynomial equal to addend1+addend2 // Neither addend1 nor addend2 should be the current polynomial bool EqualToSum(const Polynomial * addend1, const Polynomial * addend2); // Sets the current polynomial equal to minuend-subtrahend // Neither minuend nor subtrahend should be the current polynomial bool EqualToDiff(const Polynomial * minuend, const Polynomial * subtrahend); // Sets the current polynomial equal to mult1*mult2 // Neither mult1 nor mult2 should be the current polynomial bool EqualToProd(const Polynomial * mult1, const Polynomial * mult2); // Pretty prints the current polynomial to cout void Print(); private: // A polynomial is represented as a linked list of monomials, // ordered from highest degree to lowest. // No monomial in the list may have a zero coefficient. // The 0 polynomial is represented by list=NULL. Monomial * list; };