Question

Write a C++ program to compute both roots of the quadratic equation when the user provides...

Write a C++ program to compute both roots of the quadratic equation when the

user provides the three coefficients A, B, and C.

Specifically,

A.

Display “Your Name”

B.

Display “Project_2 Problem_1”

C.

Display “This program computes both roots of a quadratic equation”

D.

Display “given the coefficients A, B, and C”

E.

Real_1 = 0

F.

Real_2 = 0

G.

Imag = 0

H.

D = 0

I.

DD =0

J.

Flag = ‘Y’

K.

DO

a.

A = Display “Enter A”

b.

B = Display “Enter B”

c.

C = Display “Enter C”

d.

D = (pow(B,2.0) – 4*A*C)

e.

If D < 0 Then

i.

DD = sqrt(4*A*C – B*B)

ii.

Imag = DD/(2*A)

iii.

Real_1 = -B/(2*A)

iv.

Real_2 = -B/(2*A)

f.

If D == 0 Then

i.

Imag = 0

ii.

Real_1 = -B/(2*A)

iii.

Real_2 = -B/(2*A)

g.

If D > 0 Then

i.

Imag = 0

ii.

Real_1 = (-B + sqrt(D))/(2*A)

iii.

Real_2 = (-B – pow(D,0.5))/(2*A)

h.

Display “Solution 1 is = “ << Real_1 << “ ” << “+j” << Imag)

i.

Display “Solution 2 is = “ << Real_2 << “ ” << “-j” << Imag)

j.

Display "Do you want to run the program again? (Y = yes, N =

no)");

L.

While (Flag == ‘Y’ || Flag == ‘y’)

M.

Return (0

1 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int flag;
while(1){
   float A,B,C,x1,x2, D, real, imgnry;
   cout<<"the quadratic eqn in the form of Ax^2 + Bx + C"<<endl;
   cout<<"Enter A:";
   cin>>A;
   cout<<"Enter B:";
   cin>>B;
   cout<<"Enter C:";
   cin>>C;
   D=B*B- 4*A*C; //discriminant
   if(D>= 0)
   {
   cout<<"Roots are real but different"<<endl;
       x1=(-B+sqrt(D))/(2*A);
   x2=(-B-sqrt(D))/(2*A);
   cout<<"x1 = "<<x1<<endl; //root 1
   cout<<"x2 = "<<x2<<endl;//root 2
   }
   else if (D == 0)
   {
cout << "Roots are real and same" << endl;
x1 = (-B + sqrt(D)) / (2*A);
cout << "x1 = x2 =" << x1 << endl;
}
   else
   {
   cout<<"Roots are complex"<<endl;
       real=-B/(2*A);//real part
   imgnry =sqrt(-D)/(2*A);//imaginary part
   cout<<"x1 = "<<real<<"+"<<imgnry<<"i"<<endl; //root 1
   cout<<"x2 = "<<real<<"-"<<imgnry<<"i"<<endl; //root 2
   }
   cout<<"Do you want to run program again?press(1 = yes, 2 = No):";
   cin>>flag;
   if(flag!=1)
       break;
   }
}

M 1 2 3 4 5 6 7 8 9 10 M 11 12 13 14 15 16 17 #include <iostream> #include <cmath> using namespace std; int main() { int flagx1 X2 the quadratic eqn in the form of Ax^2 + Bx + C Enter A:1 Enter B:0 Enter C:36 Roots are complex -0+6i -0-6i Do you want

Add a comment
Know the answer?
Add Answer to:
Write a C++ program to compute both roots of the quadratic equation when the user provides...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python. The two roots of a quadratic equation ax^2 + bx + c = 0...

    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...

  • (Algebra: solve quadratic equations) The two roots of a quadratic equation, for example, , can be...

    (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....

  • Write a C program, to solve the quadratic equation a x2 + b x + c...

    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)...

  • C++ The roots of the quadratic equation ax² + bx + c = 0, a ≠...

    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...

  • The roots of the quadratic equation ax2 + bx + c = 0, a following formula:...

    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...

  • This is in python language Algebra: solve quadratic equations) The two roots of a quadratic equation,...

    This is in python language Algebra: solve quadratic equations) The two roots of a quadratic equation, for example, 0, can be obtained using the following fomula: b 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. Write a program that prompts the user to enter values for a, b, and cand...

  • Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2...

    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): ==================== Quadratic Solver coefficients a=1 b=2 c = -3 roots z1 = 1 z2 = -3

  • Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c...

    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...

  • Help with MATLAB. i did like input('enter the coefficients of a quadratic equation "Ax2 + Bx...

    Help with MATLAB. i did like input('enter the coefficients of a quadratic equation "Ax2 + Bx + C = 0"') fx=(-B+sqrt(B^2+4*A*C))/(2*A); i just dont know how i can ask the user to input three (A,B,C)? thanks! EXERCISE 6 Ask user to enter the coefficients of a quadratic equation, Ax² + Bx + C = 0, i.e. A, B, and C, and calculate the roots of the equation using the quadratic formula, ., --B+VB? - 4AC 2A

  • CSC 211 - Lab-2 Write a C++ program to find the roots of a quadratic equation...

    CSC 211 - Lab-2 Write a C++ program to find the roots of a quadratic equation ax +bx+c=0. The roots are given by the formula, x=-b I56²-4ac 2a x = -b+ √b²-4ac 2. x2 = -b-√6²-4ac 2a Instructions: 1. Type, compile, and run the program in an online C++ compiler. 2. Open a word document and copy the following items onto it: a. The source code b. Screenshot of your program's result 3. Save the word document as lastnameFirstname_Lab2.docx (for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT