CODA
Did you get your code to work ok in the end?
I copied the latest versions of each of your methods, working backwards through the messages and got the basics to run by:
# build fixes
- added
double evaluate(double theX);
to declaration of class Polynomial
- provided an implementation of
bool Polynomial::isEmpty() const
, which just tested for a null pointer
- changed the function header of operator= from
Polynomial Polynomial::operator+ (Polynomial& object)
to (i.e. added missing const)
Polynomial Polynomial::operator+ (const Polynomial& object)
- added an implementation of
ostream& operator << (ostream& out,const Term& object)
.
1 2 3 4 5 6 7 8 9
|
ostream& operator << (ostream& out,const Term& object)
{
out << object.a;
if(1 == object.n)
out << "x";
else if(0 != object.n)
out << "x^" << object.n;
return out;
}
|
# to run basics tests (i.e. building instances, adding the, displaying them) without crashing
- modified the non-default constructors so they also nulled the ember variable top
1 2
|
Polynomial(int theA) : top(NULL) {addNew(theA,0);};
Polynomial(int theA,int theN) : top(NULL) {addNew(theA,theN);}
|
- modified operator<< to put +s inbetween terms (really should use -/+ as appropriate)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
ostream& operator << (ostream& out,const Polynomial& object)
{
Term *temp = object.top;
if(temp == NULL)
out << "0";
else
{
bool show_plus = false; // new
while(temp->getLink() != NULL)
{
if(show_plus) // new
out << " + "; // new
else // new
show_plus = true; // new
out << *temp;
temp = temp->getLink();
}
if(show_plus) // new
out << " + "; // new
out << *temp;
}
return out;
}
|
BUT I didn't check operator- or operator* as I had run out of steam after looking at operator>> (see next post)