0

Poly.h

```
#include <iostream>
using namespace std;
#ifndef POLY101
#define POLY101
class Poly
{
[B]private:[/B]
int order;
double *a; // Coefficient vector -- a[0], a[1], a[2], ..., a[order]
// to represent a[0] + a[1]*x + a[2]*x^2 + ...
public:
Poly(int = 0); // Default constructor
Poly(const Poly &p); // Copy constructor
~Poly(); // Destructor (must free memory)
// Function to change polynomial size/order (dynamic memory allocation)
void Resize(int); // Resize polynomial based on new order value
// Math operators
Poly operator=(const Poly &p);
Poly operator+(const Poly &p);
Poly operator-(const Poly &p);
Poly operator*(const Poly &p);
double Evaluate(double x); // Compute and return the polynomial value at x
// Support functions
void SetCoeff(int o, double x); // Set coefficient of order o to value x
friend istream &operator>>(istream &is, Poly &p);
friend ostream &operator<<(ostream &os, Poly &p);
// Note: The Divide() function was added for convenience. It can be used
// in both the / and % functions to minimize total amount of code.
Poly operator/(const Poly &); // Returns quotient from polynomial division
Poly operator%(const Poly &); // Returns remainder from polynomial division
void Divide(const Poly &d, Poly &q, Poly &r); // d=divisor; q=quotient; r=remainder
};
#endif
```

//the alogrithm for my poly.cpp is as follows

main_test.cpp

```
#include "Poly.h"
int main()
{
Poly f, g, h, i, j;
Poly q, r;
double y;
cin >> f;
cout << "f = " << f << endl;
cin >> g;
cout << "g = " << g << endl;
h=f+g;
cout << "\n h=f+g=" << h << endl;
i=f-g;
cout << "\n i=f-g=" << i << endl;
j=f*g;
cout << "\n j=f*g=" << j << endl;
y=h.Evaluate(3);
cout << "\n h(3) = " << y << endl;
cout << "\n\n Division and remainder:\n\n";
q=f/g;
cout << "\n f/g=" << q << endl;
r=f%g;
cout << "\n f%g=" << r << endl;
return 0;
}
```

//and now when I debug my output screen should look like

test_output.cpp

Enter polynomial coefficients (decreasing power order):

1

2

1

f = 1 * x^2 + 2 * x^1 + 1

Enter polynomial order:

1

Enter polynomial coefficients (decreasing power order):

1

1

g = 1 * x^1 + 1

h=f+g=1 * x^2 + 3 * x^1 + 2

i=f-g=1 * x^2 + 1 * x^1 + 0

j=f*g=1 * x^3 + 3 * x^2 + 3 * x^1 + 1

h(3) = 20

I just need to make a code for poly.cpp looking like the main_test.cpp(it should consist of the codeed form) and as I debug poly.cpp along side poly.h the output screen should look like the

test_output.cpp