For C the task is to write the implementation for a class of

For C++ the task is to write the implementation for a class of polynomial operations. Your will write the code for: 2 constructors, a destructor, print, addition, multiplication , differentiation and integration of polynomials. The polynomials will be linked lists of TermNodes. The purpose is to use separate compilation, pointers, classes, operator overloading

Thanks

Solution

class Poly
{

private:

   //this will be the array where we store the coefficients
   double *coefficients;
//the degree of the polynomial (i.e. one less then the length of the array of coefficients)
  
   int degree;
public:
   Polynomial(); //the default constructor to initialize a polynomial equal to 0
   Polynomial(double[], int); //the constructor to initialize a polynomial with the given coefficient array and degree
   Polynomial(Polynomial&); //the copy constructor
   Polynomial(double); //the constructor to initialize a polynomial equal to the given constant
   ~Polynomial() { delete coefficients; } //the deconstructor to clear up the allocated memory
  
   //the operations to define for the Polynomial class
   Polynomial operator+(Polynomial p) const;
   Polynomial operator-(Polynomial p) const;
   Polynomial operator*(Polynomial p) const;
};

//This is what the default constructor should look like
Polynomial::Polynomial() {
   degree = 0;
   coefficients = new double[degree + 1];
   coefficients[0] = 0;
}

//You must define the rest of the functions

For C++ the task is to write the implementation for a class of polynomial operations. Your will write the code for: 2 constructors, a destructor, print, additio

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site