Question
You are to design and implement a C++ program that will solve for the roots of a quadratic equation of the form below: ax 2
You are to design and implement a C++ program that will solve for the roots of a quadratic equation of the form below:
ax2 + bx + c = 0
Input: Read in a, b, c using input entered from a text file. Use a trailer of
0 0 0 at the end of the data file.
Calculations:
d = b*b - 4ac (d=discriminant)
If the result < 0, there are no real roots to the equation
If the result = 0, there is one real root (-b/2a)
If the result > 0, there are two real roots to the equation
Root1 = -b - sqrt( b2 - 4ac)/2a
Root2 = -b + sqrt( b2 - 4ac)/2a
Exception: Do not solve for roots if a = 0 code as an error message
Output: Print a, b, c, the two roots, and/or any errors messages. Allow the user to continue executing the program until out of data using a trailer on the input data file (use a while loop like while (a != 999)) or continue until user says to stop (use a do-while loop until response is not Yes).
The output should look like this:
A B C Root 1 Root 2
6 -10 -4 ? ?
2 6 9 ? ?
. . . . .
. . . . .
Run the program with the following set of data:
6 -10 -4
2 6 9
2 4 8
0 2 4
2 4 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started