// © Copyright 1995, Joseph Bergin.  All rights reserved. 

#ifndef __Polynomial__
#define __Polynomial__

#include "Array.h"

// A Monomial is one term of a polynomial.  It represents a constant
// coefficient times a power(degree) of a variable x.  They may be
// evaluated at any real value. The degree must be >= 0.  The variable
// is implicit.  Assume that it is always x. Thus we have monomials in
// a single variable.  

// A Polynomial is built up out of monomials using the + operators.
// The default constructor gives the empty (0) polynomial. 
// A polynomial, once created, is immutable.  You can use it to generate
// new polynomials, however.  In spite of the last statement, it is still
// possible to assign a polynomial to a polynomial variable.  The variable
// will take on the new value.  It is the values that are immutable, not 
// the variables.  

class Polynomial
{	public:
		Polynomial(double coeff = 0.0, unsigned int degree = 0); // A Monomial
	//	Polynomial(const Polynomial& p);
	//	~Polynomial();
	//	Polynomial operator =( const Polynomial& p);
		unsigned int degree() const;
		double coefficient(unsigned int term) const; 
		// Give the coefficient of the monomial of degree term
		double evaluate(double x) const;
		Polynomial differentiate() const ;
		Polynomial operator +(const Polynomial& p) const;
	private:
		Polynomial(unsigned int maximumDegree); // used internally
		Array<double> _coefficients; // LOWEST coefficient first
		unsigned int _degree;    //If Const, can't assign.
	friend ostream& operator<<(ostream& os, const Polynomial& p);
};

#endif
// Possible improvements.  Add the usual arithmetic operations for polynomials.
// Provide a definite integral operation for Polynomials.  

