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 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
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...
write the PsuedoCode and the flow chart of the following: 1. draw a deck of cards...
write the PsuedoCode and the flow chart of the following: 1. draw a deck of cards from a standard deck of 52 cards until the queen of hearts is draw. how many cards did you draw?
1) Solve the given quadratic equation by using Completing the Square procedure and by Quadratic formula...
1) Solve the given quadratic equation by using Completing the Square procedure and by Quadratic formula ( you must do it both ways). Show all steps for each method and put your answer in simplest radical form possible. 2) Which part of the Quadratic Formula can help you to find the Nature of the roots for the Quadratic Equation. Explain how you can find the nature of the roots and provide one Example for each possible case with solution.
Write a simple C program to generate a chart of circle properties. Output chart “iteration” is...
Write a simple C program to generate a chart of circle properties. Output chart “iteration” is to be specified by user input. Your chart will include the radius, diameter, circumference, and Area values in a single table, and radius values will range from 0 to 50, floating point values, with three-decimal-place precision. Table should have all column entries right-justified and each column will have a heading above the entries. For example, assuming user enters a incrementation value of 5, the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT