> C++ program that accepts three real (using data type double) coefficients of a quadratic polynomial, a*x^2 + b*x + c. wh

C++ program that accepts three real (using data type double) coefficients of a quadratic polynomial, a*x^2 + b*x + c. wh

Posted at: 2014-12-18 
Examine the following:

#include

#include

#include

using namespace std;

typedef enum {

? ? quad_complex_conjugate_pair,

? ? quad_real_distinct_pair,

? ? quad_real_same_pair,

? ? quad_real_intercept,

? ? quad_infinite,

? ? quad_none

} quadtype;

int quadsolv( double a, double b, double c, double &x1, double &x2 ) {

? ? double d, s1;

? ? if ( a == 0.0 && b == 0.0 ) return c == 0.0? quad_infinite : quad_none;

? ? if ( a == 0.0 ) { x1= c == 0.0? 0.0 : -c / b; return quad_real_intercept; }

? ? d= b*b - 4.0*a*c;

? ? x1= b == 0.0? 0.0 : -b / (a+a);

? ? if ( d == 0.0 ) return quad_real_same_pair;

? ? if ( d < 0.0 ) { x2= sqrt( -d ) / (a+a); return quad_complex_conjugate_pair; }

? ? s1= sqrt( d ) / (a+a);

? ? x2= x1 - s1;

? ? x1 += s1;

? ? return quad_real_distinct_pair;

}

int main( void ) {

? ? double a, b, c, x, y;

? ? int status;

? ? cout << "Enter the three coefficients for a, b, and c (space separated):" << endl;

? ? cin >> a >> b >> c;

? ? status= quadsolv( a, b, c, x, y );

? ? switch ( status ) {

? ? case quad_complex_conjugate_pair:

? ? ? ? cout << "Complex roots are: " << x << " + " << y << " i, " <<

? ? ? ? ? ? ? ? ? ? x << " - " << y << " i" << endl;

? ? ? ? break;

? ? case quad_none:

? ? ? ? cout << "There are no solutions." << endl;

? ? ? ? break;

? ? case quad_infinite:

? ? ? ? cout << "All real and complex values solve the equation." << endl;

? ? ? ? break;

? ? case quad_real_same_pair:

? ? ? ? cout << "Real roots are both at " << x << endl;

? ? ? ? break;

? ? case quad_real_intercept:

? ? ? ? cout << "Real root is " << x << endl;

? ? ? ? break;

? ? case quad_real_distinct_pair:

? ? ? ? cout << "Real Roots are " << x << " and " << y << endl;

? ? ? ? break;

? ? default:

? ? ? ? cout << "Internal error -- impossible status value = " << status << endl;

? ? ? ? break;

? ? }

? ? return 0;

}

2nd page.



, and prints the real number roots if they exist; if they are complex, simply indicate that they are complex according to the output specifications below. The roots are the solutions for variable x that satisfy the equation: a*x^2 + b*x + c. where 0 cannot equal a.......

I can't figure this out and I'm having a total panic attack. Help, please. I attached photos of the PDF my prof sent us.