Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

help don\'t know how to write in c++ Write a C+ function called QUADRA that uses

ID: 3828982 • Letter: H

Question

help don't know how to write in c++ Write a C+ function called QUADRA that uses references or court statements (included within the function) to print out the real and imaginary parts of the solution to the quadratic equation A*x*x + B*x +C = 0; where the coefficients A, B and C are entered as in to the function. Use the following formulas in your function; If (B*B - 4*A*C > = 0) If (B*B-4*A*C >= 0) {Real1 = -B/(2*A) + sqrt(B*B-4*A*C)/(2*A); Real2 = -B/(2*A) - sqrt(B*4*A*C)/(2*A);} If (B*B-4*A*C = 0) {???} Else if (D

Explanation / Answer

#include<iostream>
#include<cmath>
using namespace std;
float Quadra(float a, float b, float c, float re1, float re2,float i1,float i2)
{
float d=(b*b-4*a*c);
if ( d>=0)
{
i1=i2=0;
re1=(-b+sqrt(d))/(2*a);
re1=(-b-sqrt(d))/(2*a);
return 1;
}
else if ( d<0)
{
re1=re2=-b/(2*a);
i1= sqrt(-d);
i2= -sqrt(-d);
return 0;
}
  
}

int main()
{
float a,b,c,r1,r2,i1,i2;
cout<<"enter a:";
cin>>a;
cout<<endl;
cout<<"enter b:";
cin>>b;
cout<<endl;
cout<<"enter c:";
cin>>c;
cout<<endl;
cout<<"coefficients a="<<a<<" b="<<b<<" c="<<c<<endl;
if(Quadra(a,b,c,r1,r2,i1,i2)==1)

{

cout<<"yields"<<endl;

cout<<"root1="<<r1<<"+i"<<i1<<endl;

cout<<"root2="<<r2<<"+i"<<i2<<endl;

}

else

{

cout<<"yields"<<endl;

cout<<"root1="<<r1<<"+i"<<i1<<endl;

cout<<"root2="<<r2<<"+i"<<i2<<endl;

}
return 0;
}

-------------------------------------------output------------------------------------------------------

enter a:4
enter b:5
enter c:9
coefficients a=4 b=5 c=9
yields
root1=-0.625+i1.36359
root2=-0.625+i-1.36359