Discussion of the Polynomial Class

Tom Kelliher, CS18

May 6, 1996

The Polynomial Class

Polynomial Class Declaration:

#ifndef __POLYNOMIAL_H
#define __POLYNOMIAL_H

#include "list.h"

class Polynomial
{
 private:
   List L;
   int degree;

 public:
   Polynomial(void) : degree(-1) {}
   ~Polynomial() {}
   // Ensure that L's copy constructor is called.
   Polynomial(const Polynomial& b) : L(b.L) {}
   const Polynomial& operator=(const Polynomial& b) { L = b.L; }

   int Degree(void);
   int SetCoefficient(int exp, double co);
   int RetrieveCoefficient(int exp, double& co);
   void Print(void);
   const Polynomial operator+(const Polynomial& b) const;
   const Polynomial operator-(const Polynomial& b) const;
   const Polynomial operator*(const Polynomial& b) const;
};

#endif

Class Data Members

Class Member Functions

Might be useful to define some private member functions.

Recall the list member functions:

   List(void) : l(NULL) {}
   ~List();
   List(const List& b);
   const List& operator=(const List& b);
   int Insert(int exp, double co);
   int Retrieve(int exp, double& co);
   int Delete(int exp);
   void Print(void);   // For testing.



Thomas P. Kelliher
Sun May 5 16:48:13 EDT 1996
Tom Kelliher