Write a C++ program that prompts the user for the coefficient of the quadratic t
ID: 3628395 • Letter: W
Question
Write a C++ program that prompts the user for the coefficient of thequadratic term, the coefficient of the linear term, and the constant term of
a quadratic equation. Your program should then compute and display the
roots of the quadratic equation. All numeric values in the output should
be displayed with five decimal places and the input and output MUST be
formatted as below. Name your source file quadraticsolver.cpp.
Your program interactions should appear as shown in the sample run. Be
sure to format the output of your program exactly as shown below.
Sample Run 1:
Enter the coefficient of the quadratic term>2.5
Enter the coefficient of the linear term>5
Enter the constant term>2.5
The solution to the equation 2.50000x^2 + 5.00000x + 2.50000 = 0.00000
is {-1.00000, -1.00000}.
Explanation / Answer
please rate - thanks
#include<iostream>
#include <iomanip>
#include<cmath>
using namespace std;
int main()
{double a,b,c;
double discriminant,denom;
cout<<"Enter the coefficient of the quadratic term>";
cin>>a;
cout<<"Enter the coefficient of the linear term> ";
cin>>b;
cout<<"Enter the constant term> ";
cin>>c;
discriminant=b*b-4*a*c;
denom=2.*a;
cout<<"The solution to the equation "<<setprecision(5)<<fixed<<a<<
"x^2+"<<b<<"x+"<<c<<"=0.00000 is ";
if(a==0)
cout<<"undefined ";
else if(discriminant<0)
cout<<"imaginary ";
else
cout<<"{"<<(-b+sqrt(discriminant))/denom<<", "
<<(-b-sqrt(discriminant))/denom<<"}. ";
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.