# Polynomial

• 04-17-2002
Unregistered
Polynomial
Hi there,

Could someone help with multiplying two polynomials. I have implemented a Polynomial class to overload the +, -, *operators...

Polynomial class{

public:
Polynomial operator+(const Polynomial &)
Polynomial operator*(const Polynomial &)

private:
int* ptr; // pointer of the first array element
int size; // size of array
}

Description: a polynomial is an array of terms (each term will contain a coefficent & an exponent). In the array, the subscript is the exponent, whereas the contents is the coefficient.

This is how the addition works. All it does is to add like terms.
// pass in a 2nd polynomial
// Polynomial Polynomial:: operator+(const Polynomial &rt) {
Polynomial tempPly(*this)
for(int i=0; i<rt.size; i++)
tempPly.ptr[i] = ptr[i] + rt.ptr[i];
return tempPly;
}

```Polynomial &Polynomial:: operator+(const Polynomial &rt) {   Polynomial *tempPly;   tempPly = new Polynomial(rt.size);   for(int i=0; i<rt.size; i++)       tempPly->ptr[i] = ptr[i] + rt.ptr[i];   return *tempPly; }```