Question

In: Computer Science

Write a program to calculate the number of results obtained when solving the quadratic equation: ax2...

Write a program to calculate the number of results obtained when solving the quadratic equation: ax2 + bx + c =0 with given real inputs a, b, and c.

C++ programming

Solutions

Expert Solution

quadratic equation: ax2 + bx + c =0

where x = ( -b± sqrt(b2-4*a*c) ) / 2*a

number of results obtained when solving the quadratic equation: ax2 + bx + c =0 with given real inputs a, b, and c.

  • if b*b < a*a*c, then roots are complex (not real)
  • if b*b == 4*a*c , then root are real and both roots are same
  • if b*b > 4*a*c,then roots are real and different .

c++ code:
#include <iostream>
#include <cmath>

using namespace std;
void roots(int a, int b, int c){
// prints root of quadratinc equation ax*2+bx+c
if (a == 0){
cout << "Invalid";
return;
}
int d = b*b - 4*a*c;
double sqrt_value = sqrt(abs(d));
  
if (d > 0){
cout<< "Roots are real and different \n";
cout << (double)(-b + sqrt_value)/(2*a)<<"\n"<< (double)(-b - sqrt_value)/(2*a);
}
else if (d == 0){
cout<<"Roots are real and same\n";
cout<<-(double)b/(2*a);
}
else // d<0
{
cout<<"Roots are complex \n";
cout<<-(double)b/(2*a) <<" + i"<<sqrt_value<<"\n"<<-(double)b/(2*a) <<"- i" <<sqrt_value;
};
}

int main()
{
int a , b , c;
cout<<"enter the co-efficient a,b and c values:\n";
cin >> a >> b >> c;
roots(a,b,c);

return 0;
}


case 1:

output:

enter the co-efficient a,b and c values:                                                                                                                      

1                                                                                                                                                             

-7                                                                                                                                                            

12                                                                                                                                                            

Roots are real and different                                                                                                                                  

4                                                                                                                                                             

3

case 2:

output:

enter the co-efficient a,b and c values:                                                                                                                    

2                                                                                                                                                           

4                                                                                                                                                           

2.3                                                                                                                                                         

Roots are real and same                                                                                                                                     

-1

case 3:

output:

enter the co-efficient a,b and c values:                                                                                                                    

1                                                                                                                                                           

4                                                                                                                                                           

5.6                                                                                                                                                         

Roots are complex                                                                                                                                           

-2 + i2                                                                                                                                                     

-2- i2

case 4:

output:

enter the co-efficient a,b and c values:                                                                                                                    

0                                                                                                                                                           

1                                                                                                                                                           

3                                                                                                                                                           

Invalid


Related Solutions

Write a program to input the coefficients of a quadratic equation and solve roots for all...
Write a program to input the coefficients of a quadratic equation and solve roots for all cases (including complex roots). VBA. x=(b ^2) - (4ac) I have it for 2 complex and 2 real and repeated. Is that all cases?
Write a program usingif-elseif-else statements to calculate the real roots of a quadratic equation ax^2+bx+c=0
Write a program usingif-elseif-else statements to calculate the real roots of a quadratic equation ax^2+bx+c=0
Draw a Flow chart and write a C++ program to solve the quadratic equation ax^2 +...
Draw a Flow chart and write a C++ program to solve the quadratic equation ax^2 + bx + c = 0 where coefficient a is not equal to 0. The equation has two real roots if its discriminator d = b2 – 4ac is greater or equal to zero. The program gets the three coefficients a, b, and c, computes and displays the two real roots (if any). It first gets and tests a value for the coefficient a. if...
Given f(x) = ax2 + k (where f(x) is a quadratic), describe when its reciprocal function...
Given f(x) = ax2 + k (where f(x) is a quadratic), describe when its reciprocal function would and would not have vertical asymptotes. Refer to the values (+,-,0) of a and k in your description. What are all the possible scenarios?
Explain in your own words how you approach solving any quadratic equation by factoring. What are...
Explain in your own words how you approach solving any quadratic equation by factoring. What are the key things you keep in mind as you’re working towards finding the answer(s)? Your explanation must be at least a few sentences long. Remember to outline your specific, step-by-step process.
Calculate the pH of a 0.45M solution of Benzonic Acid. (Use the quadratic equation to solve).
Calculate the pH of a 0.45M solution of Benzonic Acid. (Use the quadratic equation to solve).
Draw a flowchart that will calculate the roots of a quadratic equation. (java) Can someone draw...
Draw a flowchart that will calculate the roots of a quadratic equation. (java) Can someone draw it for me? and at same time explain,
Write an assembly program for the MSP430 to calculate the number of zeros and ones in...
Write an assembly program for the MSP430 to calculate the number of zeros and ones in an array. If the number of zeros is more than the number of ones, the red LED(connected to P1.0 on the MSP430 launchpad) will turn on. Otherwise, the green LED (connected to P1.6 on the MSP430 launchpad) will turn on.
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
Q4.) Calculate the work done by the air drag by solving for Wother in the equation...
Q4.) Calculate the work done by the air drag by solving for Wother in the equation below. Two terms in the equation have a value of zero. You will need the height and mass of the ball and the final velocity. U1+K1+Wother=U2+K2 height =1.22m mass=510grams final velocty =3.667m/s   Q5.) Calculate the fraction of the initial potential energy this work is (as a percentage), i.e.: WotherU1×100% Q6.) What final velocity would you expect in the absence of air resistance? Use the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT