Purpose : This program determines the roots of a quadratic equation of the form:
ID: 3617496 • Letter: P
Question
Purpose : This program determines the roots of a quadratic equation of theform: ax^2 + bx + c
**************************************************************/
//include file...
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//function prototype
Provide thefunction prototype for FindRootsProvide the function prototype for Discriminant
int main()
{
//local variables
float a, b, c; //coefficient variables from formula
char response; //Does the user want to process more equations?
bool keepGoing; //Should the program process more roots?
//we want to process at least one set of data
keepGoing = true;
//Find roots of the quadratic equation until the user is finished
while (cin && keepGoing)
{
cout << "Reading coefficients for the quadratic equation ";
//Read values in order of a, b, c
cin >>a >>b >>c;
//Determine the roots of the quadratic equation
//Put your answer to #6 here
cout << endl << endl ;
cout << "The quadratic equation " << a << "x^2 + ";
cout << b << "x + " << c ;
if (a == 0 ) {
cout << " is Not a quadratic equation ";
}else{
//Call function FindRoots to find and print the roots if any
Call the functionFindRoots
}
cout <<" Do you want to process more equations? (Y for yes, N for no)";
cin >> response;
if (response == 'N' || response == 'n')
keepGoing = false;
}
cout<<"End program..."<<endl;
return 0;
} // end of main
/**********************************************************
Function name : FindRoots
Purpose : Compute roots of a quadratic equation: b^2-4ac
Precondition : 3 coefficient of the quadratic equation
***********************************************************/
void FindRoots(float a, float b, float c)
{
float disc; //stores the discriminant of the equation
float root1, // store the larger root
root2; // stores the smaller root if exists
// compute discriminant
Call the functiondiscriminant,and assign the returned value into the variable disc.
if (disc > 0) {
Use the formulas tocalculate two roots.assign larger root to root1 and smaller root to root2
cout <<" has two roots. ";
cout << "Root1 = " << root1 << endl;
cout << "Root2 = " << root2 << endl;
} else if (disc == 0) {
Use the formulasto calculate the root.assign the root to root1
cout <<" has a single root. The root is ";
cout << root1 << endl;
} else
cout <<" has No real root. ";
}
/**********************************************************
Function name : discriminant
Purpose : Compute discriminant of a quadratic equation: b^2-4ac
Precondition : 3 coefficient of the quadratic equation
Postcondition: return the discriminant
***********************************************************/
Define thefunction discriminant.
Explanation / Answer
please rate - thanks //include file... #include #include #include using namespace std; //function prototype float discriminant(float,float,float); void FindRoots(float,float,float); int main() { //local variables float a, b, c; //coefficientvariables from formula char response; //Does the userwant to process more equations? bool keepGoing; //Should the programprocess more roots? //we want to process at least one set ofdata keepGoing = true; //Find roots of the quadratic equation until theuser is finished while (cin && keepGoing) { cout >a >>b>>c; //Determine the roots ofthe quadratic equation //Put your answer to #6here 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.