Question: complete what is missing for below code in c++ and disply it class polynomial { double a; double b; double c; double d; complex x1;

complete what is missing for below code in c++ and disply it

class polynomial

{

double a;

double b;

double c;

double d;

complex x1;

complex x2;

public:

polynomial(double v1, double v2, double v3)

{

a = v1;

b = v2;

c = v3;

d = discriminant();

}

double discriminant()

{

double d = b*b - 4 * a*c;

return d;

}

void find_roots();

void display();

};

void polynomial::find_roots()

{

if (a == 0)

{

if (b != 0 && c != 0)

x1.set_complex(-c / b, 0);

}

else if (d == 0)

{

x1.set_complex(-b / (2 * a), 0);

}

else if (d > 0)

{

x1.set_complex((-b + sqrt(d)) / (2 * a), 0);

x2.set_complex((-b - sqrt(d)) / (2 * a), 0);

}

else /* if (d < 0) */

{

x1.set_complex(-b / (2 * a), sqrt(abs(d)) / (2 * a));

x2.set_complex(-b / (2 * a), -sqrt(abs(d)) / (2 * a));

}

}

void polynomial::display() { cout << "The roots of the equation are: "; x1.display_complex(); cout << " and "; x2.display_complex(); cout << endl; }

int main() { polynomial p(1, -3, 4); p.find_roots(); p.display(); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!