I have been working on a program that creates, evaluates, adds, and subtracts
polynomials. I can successfully input, output, and evaluate the polynomials.
I am unable to get an output for the add and subtract functions. I don’t
think there is a problem with the code in the add and subtract functions.
(Although it could be there.) I am not sure about my copy constructor function
or the overloaded assignment operator function.

Main:

cout << “The sum of “ << f1 << “ and “ << f2 << “ is “ ;
add = f1 + f2;
cout << add;
cout << endl;

cout << “The difference of “ << f1 << “ and “ << f2 << “ is “;
sub = f1 – f2;
cout << sub;
cout << endl;

When I run the program, I get the following:

The sum of (whatever f1 is) and (whatever f2 is) is
The difference of (whatever f1 is) and (whatever f2 is) is

I don’t get any output for add or sub?????????????????????????????????????

If anybody can help, I would really appreciate it.
Thanks,
Tim

**********Overloading assignment operator*******************************

void polynomial::operator =(const polynomial& rhs)
{
int new_length;

new_length = rhs.degree;

if (new_length > degree)
{
delete [] coefficient;
degree = new_length;
coefficient = new double[degree + 1];
if (coefficient == NULL)
{
cout << "Error: Insufficient memory.\n";
exit(1);
}
}
int i;

for (i = 0; i <new_length; i++)
coefficient[i] = rhs.coefficient[i];

}

********************Copy constructor**************************************

polynomial::polynomial(const polynomial& f)
{

degree = f.degree;

coefficient = new double[degree + 1];

if (coefficient == NULL)
{
cout << "Error: Insufficient memory.\n";
exit(1);
}
for(int a = 0; a < degree; a++)
coefficient[a] = f.coefficient[a];
}


**************Add two polynomials***********************************


polynomial operator+(const polynomial& f1, const polynomial& f2)
{



polynomial t;


if (f1.degree >= f2.degree)
{


t.coefficient = f1.coefficient;


for(int a = 0; a < f2.degree; a++)
t.coefficient[a] += f2.coefficient[a];

}

else
{


t.coefficient = f2.coefficient;



for(int a = 0; a < f1.degree; a++)
t.coefficient[a] += f1.coefficient[a];

}

return t;

}


***************************Subtract two polynomials**************************************************


polynomial operator-(const polynomial& f1, const polynomial& f2)
{



polynomial t;


if (f1.degree >= f2.degree)
{



t.coefficient = f1.coefficient;


for(int a = 0; a < f2.degree; a++)
t.coefficient[a] -= f2.coefficient[a];


}

else
{


t.coefficient = f2.coefficient;



for(int a = 0; a > f1.degree ; a++)
t.coefficient[a] -= f1.coefficient[a];

}

return t;


}