Design a class named QuadraticEquation for a quadratic equation

. The class contains:



• Data fields a, b, and c that represents three coefficients.



• A constructor for the arguments for a, b, and c.



• Three get functions for a, b, and c.



• A function named getDiscriminant() that returns the discriminant, which is







• The functions named getRoot1() and getRoot2() for returning two roots of the equation











These functions are useful only if the discriminant is non-negative. Let these functions return 0 if the discriminant is negative.







Draw the UML diagram for the class. Implement the class. Write a test program that prompts the user to e


```
#include
using namespace std;

class QuadraticEquation
{
private:
int a;
int b;
int c;

public:
QuadraticEquation(double a, double b, double c)
: a(a), b(b), c(c)
{
}

double getA()
{
return a;
}

double getB()
{
return b;
}

double getC()
{
return c;
}

double getDiscriminant()
{
return b * b - 4 * a * c;
}

double getRoot1()
{
if (getDiscriminant() < 0)
return 0;
else
{
return (-b + getDiscriminant()) / (2 * a);
}
}

double getRoot2()
{
if (getDiscriminant() < 0)
return 0;
else
{
return (-b - getDiscriminant()) / (2 * a);
}
}
};

int main()
{
cout << "Enter a, b, c: ";
double a, b, c, discriminant, r1, r2;
cin >> a >> b >> c;

QuadraticEquation equation(a, b, c);
discriminant = equation.getDiscriminant();

if (discriminant < 0)
{
cout << "The equation has no roots" << endl;
}
else if (discriminant == 0)
{
cout << "The root is " << equation.getRoot1() << endl;
}
else // (discriminant >= 0)
{
cout << "The roots are " << equation.getRoot1() << " and "
<< equation.getRoot2() << endl;
}

return 0;
}
```

Computer Science & Information Technology

You might also like to view...

Static text cannot be changed after the document plays in Flash Player.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Which of the following statements is not true about recommendations displayed by the Performance Analyzer tool?

A) They can be fixed automatically by the tool. B) They carry a much higher risk. C) They are identified by an exclamation point. D) They carry very low risk.

Computer Science & Information Technology

____________________ involves the use of active investigation methods to gather information about a system or an infrastructure directly.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

A delimiter is the character used to separate rows of text in a data table

Indicate whether the statement is true or false.

Computer Science & Information Technology