Polynomial Program
// Author: Julius Dichter
#ifndef __Poly_SEEN
#define __Poly_SEEN
#include <iostream>
using namespace std;
class Poly
{
public:
Poly() { pol = NULL; } // default constructor
Poly(const int* p, int terms); // constructor
Poly operator+(const Poly& q) const; // poly addition
Poly operator-(const Poly& q) const; // poly subtraction
Poly operator*(const Poly& q) const; // poly multiplication
Poly derivative();
bool increasing(double xVal);
double defIntegralAt(double, double);
double eval(double);
unsigned int deg() const // degree
{
return(pol[0] > 0 ? pol[0] : 0);
}
void display() const; // display host object
friend ostream & operator << (ostream & out, const Poly & p);
private:
int length() const; // length of pol
int* pol;
};
#endif
Polynomial Program
The Test program will display the following output.
NOTE that the display method should produce the exact output sgow, so you will need to modify it.
// Polynomial Test Program
#include "Poly.h"
int main(int argc, char * argv[])
{
using namespace std;
int p[] = { 7,-2,3,3,2,-17,0,9 };
int q[] = { 8,2,7,3,3,-3,2,17,0,9 };
Poly p1(p, 4);
Poly q1(q, 4);
Poly sum = p1 + q1;
[Link]();
cout << endl;
return 0;
}
------------------------------ program output -----------------
(2x^8 + 1x^7 + 9)
So you will define the following methods
Poly derivative();
bool increasing(double xVal);
double defIntegralAt(double xLow, double xHigh);
double eval();
Poly operator-(const Poly& q) const; // poly subtraction
friend ostream & operator << (ostream & out, const Poly & p);
The display method will be modified to output as shown above. The operator << listed
above should print the same output as the display method, so it will be easy after you
correct the display method to output a polynomial like this: (2x^8 + 1x^7 + 9)
void display() const; // display host object
Your program will read a few polynomials from a file, and I will supply new client
program to test your code in a few days. The operator – will be similar to the operator +
so use that method as a model for your operator –
Polynomial Program
The rest of the code for Poly in the class notes can be used in your project directly. I
will discuss the logic for all the new methods in class.
I will supply a new client program which reads a polynomials from a text file. I will
also supply the text file. You need to write al the new overloaded methods so that my
client program will run correctly.
Polynomial Program