Here is the answer for the following problem. I have tried to make it as simple as possible.
However if you feel any problem in understanding the code please feel free to ask.
Code:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
//data variables
double a, b, c;
double discriminant, root_1, root_2, realPart, imagPart;
cout << "Enter cofficient a: ";
cin >> a;
cout << "Enter cofficient b: ";
cin >> b;
cout << "Enter cofficient c: ";
cin >> c;
//find the discriminant, which determine the nature of roots
discriminant = b * b - 4 * a * c;
// condition for real and different roots
if (discriminant > 0) {
root_1 = (-b + sqrt(discriminant)) / (2 * a);
root_2 = (-b - sqrt(discriminant)) / (2 * a);
cout << "Root1: " << root_1 << endl;
cout << "Root2: " << root_2 << endl;
}
// condition for real and equal roots
else if (discriminant == 0) {
root_1 = root_2 = -b / (2 * a);
cout << "Root1: " << root_1 << endl;
cout << "Root2: " << root_2 << endl;
}
// if roots are not real
else {
realPart = -b / (2 * a);
imagPart = sqrt(-discriminant) / (2 * a);
cout << "Root1: " << realPart << "+" <<
imagPart << "i" << endl;
cout << "Root2: " << realPart << "-" <<
imagPart << "i" << endl;
}
return 0;
}
--------------------------------------------------------------------------------------------------------------------------------
Output:
No real roots

Two Real roots
One real roots
reword m the program into a design document diregard the m Write a C++ program that...
The roots of the quadratic equation ax2 + bx + c = 0, a following formula: 0 are given by the In this formula, the term i2 - 4ac is called the discriminant. If b4ac 0 then the equation has a single (repeated) root. If -4ac > 0, th equation complex roots. Write a program that prompts the user to input the value of a (the coefficient of ), b (the coefficient of x), and c (the n has two...
C++ The roots of the quadratic equation ax² + bx + c = 0, a ≠ 0 are given by the following formula: In this formula, the term b² - 4ac is called the discriminant. If b² - 4ac = 0, then the equation has a single (repeated) root. If b² - 4ac > 0, the equation has two real roots. If b² - 4ac < 0, the equation has two complex roots. Instructions Write a program that prompts the...
In Python. 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...
Using C++ For this program you are going to create a class that helps to solve the quadratic equation. The equation has the following form: ax2 + bx + c = 0 The roots of the equation are: x1 = -b + sqrt(b2 - 4 * a * c) and x2 = -b - sqrt(b2 - 4 * a * c) The phrase in the parenthesis is called the discriminant. If the value of the discriminant is positive, the equation...
4-6 on matlab
4. Write a program in a script file that determines the real roots of a quadratic equation ax2+bx+c 0 When the file runs, it asks the user to enter the values of the constants a, b, and c. To calculate the roots of the equation the program calculates the discriminant D, given by: D b2-4ac When D 0, the program displays message "The equation has two roots," and the roots are displayed in the next line. When...
Write a C program, to solve the quadratic equation a x2 + b x + c = 0 of given coefficients a, b and c. When running the program, it prompts for the input of coefficients a,b,c as floating numbers. After inputting three floating numbers, it computes and prints out the solutions, then prompts for another round of input. Your program will quit when getting input 0,0,0. Your program should handle four situations: (1) a=0, not a quadratic equation; (2)...
Rule book: 1.)Must be Python - 2.) no imported module (ie cmath) - no can do on the imports... pure code.. 3.) numbers are float - not integer. Here's the prompt: (Algebra: solve quadratic equations) 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...
c++ language
TECH 1211 Computer Programming Name Test 2 Hands-On-Program B Spring 2020 Write a program that uses the quadratic formula to solve quadratic equations. Background Given the format for a quadratic equations: aX? +BX+C =0 The coefficient of the X term is the number a. The coefficient of the X term is the number b. The value of c is any non-zero constant. These values can be positive, negative or zero. You can find the solution to this equation...
(Algebra: solve quadratic equations) The two roots of a quadratic equation, for example, , can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac) / (2a) and r1 = (-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 real roots....
Use Python Programming.
Design a class named Quadratic Equation for a quadratic equation ax + bx+c 0. The class contains: • The data fields a, b, and c that represent three coefficients. . An initializer for the arguments for a, b, and c. • Three getter methods for a, b, and c. • A method named get Discriminant() that returns the discriminant, which is b- 4ac The methods named getRoot 1() and getRoot 2() for returning the two roots of...