Question

Write a program in C++ to find the solution to a polynomial, given the coefficients A,...

Write a program in C++ to find the solution to a polynomial, given the coefficients A, B, C in the equation below.

Ax^2 + Bx + C = 0

Use the quadratic equation, there should be 2 solutions. The solutions should have 2 decimal places

Sample output is given below.

Enter coefficient A: 1

Enter coefficient B: -1

Enter coefficient C: -6

The two solutions to this equation are 3.00 and -2.00

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

- 0 X CUsers ANSHUMAN GAURAV Desktop HomeworkLib\quad cpp - Dev-C++ 5.11 File Edit Search View Project Execute Tools Style Window Help TOM-GCC 4.5.2 64-bit Profiling V quad.cpp include <iostream #include <math> include <iomanip> // included so that two decimal precision could be printed using namespace std; 5 int main() noat a, b, c, rooti, root2, discriminant, real part, ing part: cout <"Enter coefficients : : cout << "Enter coefficients : cin >> b: cout << "Enter coefficients C: "; cin >> C: discriminant -b'b - 4 a c: // there may be 3 cases: 1. when both the roots are distinct, 2. when both the roots are same, 3. When both the roots are imaginary. 17 if (discriminant > 0) cout<<setprecision (2) <<fixed; // this is a feature in cur which helps to print till the desired decimal points root! - (-b + azt (discriminant))/(2a); root2 - (-) -sqrt(discriminant))/(2a); cout << "The two solutions to this equation are "<<root<<" and "<root2<cendin: 23 else if (discriminant = 0) cout<<setprecision (2) fixed; cout << "Roots are real and game." << endl; rootl - (-b + sqrt(discriminant))/(2a): cout << "rootl - root2 - < rootl << endl; 29 else real part --b/(2a) ngpart -9990 (-discriminant)/12*2); cout<<setprecision (2) <<fixed; cout << "Roots are complex and different." << endl; cout << "rootl -" << real_part << "+" <ing_part << "1" << endl; cout << "root2 -" « real_part << "-" << ing_part << "i" << endl; return 0; Compiler Line: 17 Resources hy Compile Log Debug Col5 Set D Lines 38 ? Find Results Length: 1530 Overwrite Done parsing in 0.016 seconds AA 02-30 ENG 25-01-2020 1

Add a comment
Know the answer?
Add Answer to:
Write a program in C++ to find the solution to a polynomial, given the coefficients A,...
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
  • 10) p. 53, problem 2.4.7. Write a Python program that uses the Quadratic Formula to calculate...

    10) p. 53, problem 2.4.7. Write a Python program that uses the Quadratic Formula to calculate the real solutions to an equation in the form x 2 +bx+c=0 . Prompt the user to enter values for a, b, and c, then display the solutions. For the purposes of this assignment, you may assume that every equation will have two distinct, real solutions. Put your program in the Homework 1 folder on your K: drive. Here is a sample run of...

  • Question 4: Provide at least 4 test cases. Prompt the user to input 3 doubles, a,...

    Question 4: Provide at least 4 test cases. Prompt the user to input 3 doubles, a, b and c. Which will represent the coefficients in the quadratic equation ax2 + bx + c = 0. Print out the solutions (if any) of the quadratic equation. If no root exists (this happens if a == 0, or b2 <4ac) print the message No real root. Sample input/ user entries shown in red Corresponding output Enter a, b and c which represent...

  • c++ language TECH 1211 Computer Programming Name Test 2 Hands-On-Program B Spring 2020 Write a program...

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

  • please answer this question with python. Write a program to solve the quadratic equation ax^2 +...

    please answer this question with python. Write a program to solve the quadratic equation ax^2 + bx + c = 0 using the standard quadratic formula x = -b plusminus Squareroot b^2 - 4ac/2a or the alternative formula x = 2c/-b Squareroot b^2 - 4ac. Your program should accept values for the coefficients a, b, and c as input and produce the two roots of the equation as output. Your program should detect when the roots are imaginary, but need...

  • write easiest program to under stand:- a) Python program that takes three coefficients (a, b, and...

    write easiest program to under stand:- a) Python program that takes three coefficients (a, b, and c) of a Quadratic equation (ax2+bx+c=0) as input and compute all possible roots b).User defined function isprime(num) that accepts an integer argument and returns 1 if the argument is prime, a 0 otherwise. Write a Python program that invokes this function to generate prime numbers between the given ranges

  • CODE MUST BE IN C++ Objective Create a program that provides the solution to a quadratic...

    CODE MUST BE IN C++ Objective Create a program that provides the solution to a quadratic equation. Background: A quadratic equation can be generalized by equation below: f ( x )=ax2+ bx +c Closed form solutions can be found for the zeros of a quadratic function conveniently. That is the locations where the function is equal to zero can be found by the following equation: x=− b± √ b −4ac 2a Note that depending on the sign of the expression...

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

  • (1 point) In this problem you are asked to convert the general standard form of a quadratic polynomial into the complet...

    (1 point) In this problem you are asked to convert the general standard form of a quadratic polynomial into the completed square form. Suppose f(x) = Ax + Bx+ C where A, B, and C are the coefficients of the quadratic polynomial, and A 0. Thenf can be written as f(x) = a(x - h) + k where = D h = ,and k = Enter your answers as algebraic expressions in A, B, and C. Remember that WeBWorK (and...

  • 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

  • I. Design the C++ code for a program which will use the Pythagorean Theroem to calculate...

    I. Design the C++ code for a program which will use the Pythagorean Theroem to calculate and display the length of a right triangle hypotenuse,c, given the lengths of its adjacent sides: a and b.. (hint: a^2 + b^2 = c^2) II. Design the C++ code for a program which will calculate and display the roots of a quadratic equation of the form ax^2 + bx + c = 0, given its coefficients, a, b, and c.

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
ADVERTISEMENT