title: A polynomial class
body: <p>Here is the problem I am trying to solve: </p>
  
  <blockquote>
    <p>Using dynamic arrays, implement a polynomial class with polynomial addition,
    subtraction, and multiplication. Discussion: A variable in a polynomial does nothing but act as a placeholder for
    the coefficients. Hence, the only interesting thing about polynomials is the array
    of coefficients and the corresponding exponent. Think about the polynomial
    x<em>x</em>x + x + 1
    Where is the term in x*x ? One simple way to implement the polynomial class is to
    use an array of doubles to store the coefficients. The index of the array is the
    exponent of the corresponding term. If a term is missing, then it simply has a zero
    coefficient.
    There are techniques for representing polynomials of high degree with many missing
    terms. These use so-called sparse matrix techniques. Unless you already know
    these techniques, or learn very quickly, do not use these techniques.
    Provide a default constructor, a copy constructor, and a parameterized constructor
    that enables an arbitrary polynomial to be constructed.
    Supply an overloaded operator = and a destructor.
    Provide these operations:
    polynomial + polynomial, constant + polynomial, polynomial + constant,
    polynomial - polynomial, constant - polynomial, polynomial - constant.
    polynomial * polynomial, constant * polynomial, polynomial * constant,
    Supply functions to assign and extract coefficients, indexed by exponent.
    Supply a function to evaluate the polynomial at a value of type double .
    You should decide whether to implement these functions as members, friends, or standalone functions.</p>
  </blockquote>
  
  <p>This is not for a class, I am just trying to teach myself C++ because I need it as I will start my graduate studies in financial mathematics at FSU this fall. Here is my code thus far:</p>
  
  <pre><code>class Polynomial
  {
  private:
      double *coefficients; //this will be the array where we store the coefficients       
      int degree; //this is the degree of the polynomial (i.e. one less then the length of the array of coefficients)
  
  public:
      Polynomial(); //the default constructor to initialize a polynomial equal to 0
      Polynomial(double coeffs[] , int nterms); //the constructor to initialize a polynomial with the given coefficient array and degree
      Polynomial(Polynomial&amp;); //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  the default constructor 
  Polynomial::Polynomial() {
      degree = 0;
      coefficients = new double[degree + 1];
      coefficients[0] = 0;
  }
  
  //Initialize a polynomial with the given coefficient array and degree
  Polynomial::Polynomial(double coeffs[], int nterms){
      degree = nterms;
      coefficients = new double[degree]; //array to hold coefficient values
      for(int i = 0; i &lt; degree; i++)
          coefficients[i] = coeffs[i];
  }
  
  Polynomial::Polynomial(Polynomial&amp;){
  
  }
  
  //The constructor to initialize a polynomial equal to the given constant
  Polynomial::Polynomial(double){
  
  }
  
  Polynomial::operator *(Polynomial p) const{
  
  }
  
  Polynomial::operator +(Polynomial p) const{
  
  }
  
  Polynomial::operator -(Polynomial p) const{
  
  }
  </code></pre>
  
  <p>I am just wondering if I am on the right track, if there is a better way of doing this please let me know. Any comments or suggestions would be greatly appreciated.</p>