Question

In: Computer Science

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 this

value is zero, the program displays an error message and terminates, otherwise it proceeds to

get a value for the coefficient b and a value for the coefficient c. Next it computes and tests the

discriminator d = b^2 – 4ac. If the discriminator d is negative, the program displays an error

message “No Real Roots!!” and terminates, otherwise it proceeds to compute and display the two

real roots R1 and R2 according to the following formulas:

R1 =

−b+√b

2−4ac

2a

and R2 =

−b−√b

2−4ac

2a

Solutions

Expert Solution

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double a,b,c,d,r1,r2;
//input coefficient a
cout<<"Enter a: ";
cin>>a;
if(a==0)
{
cout<<"Coefficient a must not be equal to 0"<<endl;
}
else
{
//input coefficients b and c
cout<<"Enter b and c: ";
cin>>b>>c;
//calculate discriminant
d=(b*b)-(4*a*c);
if(d<0) //no real roots
cout<<"No Real Roots!!"<<endl;
else
{
//calculate roots
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
cout<<"Roots are r1= "<<r1<<" and r2= "<<r2<<endl;
}
}
}

Output


Related Solutions

1. Solve quadratic equation Ax^2+Bx+C=0 using the quadratic formula x = (-B+ and - sqrt(B^2-4ac)) /...
1. Solve quadratic equation Ax^2+Bx+C=0 using the quadratic formula x = (-B+ and - sqrt(B^2-4ac)) / 2a) and output the two solution with clear explanation could you please do it in MATLAB
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
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?
use Java The two roots of a quadratic equation ax^2 + bx + c = 0...
use Java The two roots of a quadratic equation ax^2 + bx + c = 0 can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac)) / (2a) and r2 = (-b - sqrt(b^2 - 4ac)) / (2a) b^2 - 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no...
Write a C++ program that solves a quadratic equation to find its roots. The roots of...
Write a C++ program that solves a quadratic equation to find its roots. The roots of a quadratic equation ax2 + bx + c = 0 (where a is not zero) are given by the formula (–b ± sqrt(b2 – 4ac)) / 2a *Use #include for the use of sqrt. The value of the discriminant (b2 – 4ac) determines the nature of roots. If the value of the discriminant is zero, then the equation has a single real root. If...
Write a Diophantine Equation program in C++. Find integer solutions to Ax + By = GCD...
Write a Diophantine Equation program in C++. Find integer solutions to Ax + By = GCD (A, B) Ex: a = 3, b = 6, c = 9 a = 2, b = 5 , c = 1
Using excel UserForm construct a Flowchart that solves a quadratic equation ax^2+bx+c=0 for changingvalues of a,...
Using excel UserForm construct a Flowchart that solves a quadratic equation ax^2+bx+c=0 for changingvalues of a, b and c. Please also display the code you have used. Please use excel UserForm Thanks
IN C++ The Quadratic equation is used to solve for the variable x where the function...
IN C++ The Quadratic equation is used to solve for the variable x where the function evaluates to zero. However there is actually two answers returned by the quadratic equation. Can we solve for the quadratic equation using just one call to a function you write? Hint : create a function that does not 'return' anything. Takes three parameters a,b,c as double.s   And had two more parameters that are passed by reference to two doubles that are the two answers...
FOR JAVA Define a class QuadraticExpression that represents the quadratic expression ax^2 + bx + c:...
FOR JAVA Define a class QuadraticExpression that represents the quadratic expression ax^2 + bx + c: You should provide the following methods (1) default constructor which initalizes all the coefficients to 0 (2) a constructor that takes three parameters public QuadraticExpression(double a, double b, double c) (3) a toString() method that returns the expression as a string. (4) evaluate method that returns the value of the expression at x public double evaluate(double x) (5) set method of a, b, c...
FOR JAVA Define a class QuadraticExpression that represents the quadratic expression ax^2 + bx + c:...
FOR JAVA Define a class QuadraticExpression that represents the quadratic expression ax^2 + bx + c: You should provide the following methods (1) default constructor which initalizes all the coefficients to 0 (2) a constructor that takes three parameters public QuadraticExpression(double a, double b, double c) (3) a toString() method that returns the expression as a string. (4) evaluate method that returns the value of the expression at x public double evaluate(double x) (5) set method of a, b, c...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT