Polynomials, classes and member functions

Hello

I'm currently in the process of implementing a Polynomial ADT - we have a class declaration file, and from that I need to perform an implementation that does a couple of things with the polynomial.

the polynomials use int a, b, c; A situation where a = 2, b = 3 and c = -1 would make one as such:

2x^2+ 3b - 1 = 0

I'm currently working with the member functions:

1
2
3
4
bool hasRealSolution();
double getRealSolution1();
double getRealSolution2();
string str();


hasRealSolution returns true if the equation has a real solution (or 2), while getRealSolution1 and getRealSolution2 assume that a real solution exists and return these solution(s).

I have no idea how to approach this problem. I currently have the first member function implemented to something that like this:

1
2
3
4
5
6
7
bool Polynomial:: hasRealSolution();
{
if (SOMETHING GOES IN HERE??)
return 1;
else
return 0;
}


My math isn't so good, and I'm not sure what I should be doing for this boolean check and the other two solutions.
Last edited on
2x^2+3b-1? Isn't that 'b' suppose to be a 'x'?

If you only have to deal with quadratics it works as hamsterman's link posted. Basically check if the part of the quadratic formula known as the discriminate (b^2-4ac) is negative. If so, there is no real solutions.

If you need to deal with polynomials greater than degree 2, you're gonna need a different method.
Topic archived. No new replies allowed.