HW computer science
ECE-206 HW-08A Page 1 of 1
HW-08A: C++ Quadratic Equation
Write a C++ program to find the roots of a quadratic equation of the form Ax2 + Bx + C = 0.
Prompt the user to enter the coefficients A, B, and C. The program can only handle real roots;
thus, the program must reject the coefficients if the discriminant (B2 – 4AC) < 0. In addition, the
program must treat the quadratic equation as a special case, a linear equation, when A is zero.
Thus, no division by zero will occur in your program.
Output Format
Allocate at least 15 spaces for each of the root output and output the roots in the following
format:
1. Right justified, four decimal places accuracy, fixed point format
2. Right justified, two decimal places accuracy, floating point (scientific) format
3. Left justified, four decimal places accuracy, fixed point format
4. Left justified, two decimal places accuracy, floating point (scientific) format
Run output example
If the program run with A = 2, B = -9, and C = 5, the run output will look like
The roots of 2 x*x - 9*x + 5 = 0 are
x1 x2
123456789012345678901234567890 (digit position)
3.8508 0.6492
3.85e+000 6.49e-001
3.8508 0.6492
3.85e+000 6.49e-001
Submit a copy of the working and well-documented program, and run output.
Note: use sqrt() function in cmath library to do the square root.