Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

In Exercises 2132, calculate the derivative. (x) = 2x 3 3x 2 + 2x

Answered: 1 week ago