# linked lists of a polynomial

• 02-11-2002
Unregistered
Hi every one, I'm very new in c++ programming, and I'm encounting some difficulties with my program. It's supposed to create a polynomial with a linked list. It keeps giving me errors and I don't know what to do anymore. The polynomial is created with a single nested statement in the constructor. But it doesn't seem to work. Please help me.

class Term
{
public:
Term (double coefficient, int exponent=0, Term *next=NULL);
double evaluate (double x);
void print();
private:
double coefficient;
int exponent;
Term *next;
};

Term::Term(double coefficient, int exponent = 0, Term *next = NULL)
{
Term *pt = new Term(1,10, new Term(-3,4,new Term (17)));
}

double Term::evaluate (double x);
{
if (Term *pt != NULL)
{
while(pt->next != NULL)
{
int expo = pt->exponent;
double accum+ = pt->coefficient * pow(x, expo);
pt=pt->next;
}
pt->next = NULL;
}
return accum;
}

int main()
{
Term test;
double result = test.evaluate (2);
cout << "and the answer is: " << result << endl;
return 0;
}
• 02-11-2002
golfinguy4
Term test;
double result = test.evaluate (2);//this is where your problem is

it should be the following

Term test (2);
double result=test.evaluate;

I haven't looked over the rest of your code but check this and come back later if it still doesn't work.
• 02-11-2002
sean
Just a a suggestion - using polynomials in an algorithm will make things pretty complex if you do any circular logic or anything - I would suggest breaking any trinomials into two smaller binomials that co-complement.
• 02-11-2002
Unregistered
I don't think my problem is in the declaration of my class Term instance. Look further down, and you'll see that the function evaluate does receive a double (x) and return one.
Here are a couple of the errors I get

error C2572: 'Term::Term' : redefinition of default parameter : parameter 3
question2.cpp(8) : see declaration of 'Term::Term'
'Term::Term' : redefinition of default parameter : parameter 2
error C2447: missing function header (old-style formal list?)
• 02-11-2002
golfinguy4
O, sorry, I thought that the double you inputted into evaluate was was u were trying to use to set as the coefficient.

I am kinda busy right now but I'll try to help u later.