Source: assign2_polynomial_kdoc.h




/******************************************************************
* Memorial University of Newfoundland
* Engineering 4892 Data Structures
*
* $RCSfile$ $Revision$
* $Date$
* $State$
*
* Include file for Assignment 2.
*
******************************************************************/
/******************************************************************
* REVISION HISTORY
*
* $Log$
*
******************************************************************/
#ifndef ASSIGN2_POLYNOMIAL_DEF
#define ASSIGN2_POLYNOMIAL_DEF
#include
/**
* A class for representing univariate polynomials of the form
* c_{d}x^{d} + c_{d1}x^{d1}
* + ... + c_{1}x + c_{0}.
*
* @author Dennis Peters
*
* Representation:
*
*  c  a sequence of Reals which are the coefficients
*
*/
class Polynomial {
public:
// Constructors
/**
* noagrument constructor
*
* Post: c = _
*/
Polynomial() { /* you don't need to implement this one */ }
/**
* Constructor.
*
* @param d the degree of the polynomial
* @param coefs pointer to an array containing the
* coefficients in ascending order
* (i.e., coefs[0]
is c_0). Note
* that the number of coefficients should be
* one more than the degree.
*
* Pre: d
>= 0
* Post: d
= 0 > c = _ /\
* d
!= 0 > c = coefficients from coefs
*/
Polynomial(int d = 0, double *coefs = NULL);
// Default copy constructor, assignment operator and destructor used
// Convince yourself that this is appropriate in this case.
// Accessors
/**
* evaluate the polynomial at x
*
* @param x value to evalute the polynomial at
* @return the value of this polynomial evaluated at x
*
* Pre: this.degree() >= 0 (i.e., the polynomial is defined)
*/
double operator() (double x) const;
/**
* degree of the polynomial
*
* @return the degree (i.e., exponent of highest order coefficient)
* of this polynomial or 1 if the polynomial is undefined
*/
int degree() const;
// Mutators
/**
* add a polynomial to this
*
* Post: c' = [c_{0} + r_{0},
* c_{1} + r_{1} ... ] /\ Result = *this
*
* @return this + r
*/
Polynomial& operator += (const Polynomial& r);
/**
* multiply a polynomial by this
*
* Post: c' = coefficients for product (this * r) /\ Result = *this
*
* @return this * r
*/
Polynomial& operator *= (const Polynomial& r);
private:
// Representation:
// coef contains the coefficients, starting with the lowest order
// coefficient (i.e., c_0).
std::list coef;
};
#endif
Generated by: dpeters on delphi.engr.mun.ca on Thu May 22 23:07:50 2003, using kdoc 2.0a53. 