Quadratic Equation Code

I'm trying to create a code which will solve a quadratic equation ax^2+bx+c=0 where the user inputs the a, b, and c and the output is the roots p and q respectively, using only class and object definitions. I know i have to have a class set up for real numbers and a second one for complex numbers but im unsure of how to go about that exactly.
complex and real are both built into c++

complex<double> c; //complex
double d; //real
c = sqrt(c); //built in also

c.imag, c.real are the parts of the built in class.

can you do it now?

eg..
d = -2;
c = sqrt(d);
cout << c.imag <<" " << c.real << endl;
Last edited on
So what problems are you having?

I assume you are going to use the Quadratic Formula to solve the equation. How far have you gotten in coding this algorithm?
basically,you don't need a class to do this.
as jonnin said,you can deal with complex numbers in c++ through the complex library,just do this:
 
 #include <complex>  

and you're ready to go.
Tip:when calculating the complex roots,just calculate one root and then take it's conjugate.
http://www.cplusplus.com/reference/complex/
Topic archived. No new replies allowed.