Project 1 - Polynomial Class

Project 1 - Polynomial Class - Robert J. England II COS 221...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Robert J. England II COS 221 Project 1 Polynomial Class Project done for Prof. Larry Latour Wednesday, October 11, 2006
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The following is the actual code used in the program. There are two classes; one is the Polynomial class, which provides the bulk of the code; the other is the Test class, which tests the Polynomial class extensively. The main program does nothing more than create a Test object, and the constructor of that object performs all of the testing. // Polynomial.cpp : // Polynomial class created by Robert J. England II // for COS 221 with Larry Latour // at the University of Maine in Orono // Friday, October 6, 2006 // #include "stdafx.h" #include <iostream> #include <math.h> #include "chplot.h" using namespace std; class Polynomial { public : // Constructors Polynomial(); // POST: A polynomial equivalent to zero is created Polynomial( double a0); // POST: A polynomial equivalent to constant a0 is created Polynomial(Polynomial & source); // POST: A new polynomial equivalent to this polynomial is // created // Clone method Polynomial clone(); // POST: A new polynomial equivalent to this polynomial is // created and returned // Modification methods void addToCoef( double amount, int k); // PRE: k >= 0 // POST: The value amount is added to the kth coefficient of the // polynomial void assignCoef( double newCoefficient, int k); // PRE: k >= 0 // POST: The kth coefficient of the polynomial is changed to the // value newCoefficient void clear(); // POST: The polynomial is set equivalent to zero void reserve( int newSize); // PRE: size must be greater than the current degree of the // polynomial // POST: Memory is reserved for size coefficients for the // polynomial // Accessor methods double coefficient( int k); // PRE: k >= 0 // POST: The kth coefficient of the polynomial is returned // If the degree of the polynomial is less than k, 0 is returned int getDegree() { return degree;};
Background image of page 2
// POST: The degree of the polynomial is created int nextTerm( int k); // POST: The next greater nonzero coefficient above k is // returned; if k is the greatest coefficient, -1 is returned; // if k is negative, function finds first nonzero coefficient // Evaluation method double evaluate( double x); // POST: The value of the polynomial at value x is returned // Arithmetic operators Polynomial operator + (Polynomial other); // POST: The algebraic sum of the polynomials is returned Polynomial operator - (Polynomial other); // POST: The algebraic difference of the polynomials is returned Polynomial operator * (Polynomial other); // POST: The algebraic product of the polynomials is returned Polynomial derivative(); // POST: The derivative of the polynomial is returned // Plot method void Polynomial::plotPoly( double low, double high, int res, char * title); // PRE: high > low; res > 0 // POST: The polynomial is plotted between values low and high, // with resolution res and graph title title private : // data fields double * coefficients; int degree; int size; }; Polynomial::Polynomial()
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/19/2008 for the course COS 221 taught by Professor Latour during the Fall '06 term at University of Maine Orono .

Page1 / 16

Project 1 - Polynomial Class - Robert J. England II COS 221...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online