Purpose : This program calculates the number of roots of a quadratic equation. W
ID: 3617493 • Letter: P
Question
Purpose : This program calculates the number of roots of a quadraticequation. When the discriminant of a quadratic equation is negative
there is no real root, if zero one real root, if positive two real
roots exist for the quadratic equation.
**************************************************************/
/*include file...*/
#include <iostream>
#include <iomanip>
using namespace std;
Function prototypeof discriminant function
int main()
{
//local variables
float a, b, c; //coefficient variables from formula
float disc; //stores the discriminant of the equation
//Program starting
cout <<" Program starting.... ";
//Read values in order of a, b, c
cin >>a >>b >>c;
// compute discriminant
Call the functiondiscriminant,and assign the returned value into the variable disc.
cout << "The value of the discriminant is "
<< fixed << setprecision(2) << disc << endl;
if (disc < 0)
{ //If discriminant is negative
cout <<"No real roots"<<endl;
} else if (disc == 0)
cout << "One real root"<<endl;
else //Otherwise (positive)
cout <<"Two real roots" <<endl;
cout<<"End program..."<<endl;
return 0;
} // end of main
/**********************************************************
Function name : discriminant
Purpose : Compute discriminant of a quadratic equation: b^2-4ac
Precondition : 3 coefficient of the quadratic equation
Postcondition: return the discriminant
***********************************************************/
create thefunction definition of discriminant function
Explanation / Answer
please rate - thanks #include #include #include using namespace std; float discriminant(float,float,float); int main() { //local variables float a, b, c; //coefficient variablesfrom formula floatdisc; //stores the discriminant of theequation //Program starting cout b >>c; // compute discriminant disc=discriminant(a,b,c); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.