Question
c++ language
TECH 1211 Computer Programming Name Test 2 Hands-On-Program B Spring 2020 Write a program that uses the quadratic formula to
Sample 1 Please enter the coefficient of the squared ters, State or the coefficient of the to the first power tare, Please en
Sample 3 Display Your Name Here Please enter the coefficient of the x squared tere, at Please enter the coefficient of the x
0 0
Add a comment Improve this question Transcribed image text
Answer #1
 #include <iostream> #include <cmath> using namespace std; int main() { float a, b, c, x1, x2, discriminant, realPart, imaginaryPart; cout << "Enter coefficients a, b and c: "; cin >> a >> b >> c; discriminant = b*b - 4*a*c; if (discriminant > 0) { x1 = (-b + sqrt(discriminant)) / (2*a); x2 = (-b - sqrt(discriminant)) / (2*a); cout << "Roots are real and different." << endl; cout << "x1 = " << x1 << endl; cout << "x2 = " << x2 << endl; } else if (discriminant == 0) { cout << "Roots are real and same." << endl; x1 = (-b + sqrt(discriminant)) / (2*a); cout << "x1 = x2 =" << x1 << endl; } else { realPart = -b/(2*a); imaginaryPart =sqrt(-discriminant)/(2*a); cout << "Roots are complex and different." << endl;
Add a comment
Know the answer?
Add Answer to:
c++ language TECH 1211 Computer Programming Name Test 2 Hands-On-Program B Spring 2020 Write a program...
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
  • 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...

  • reword m the program into a design document diregard the m Write a C++ program that...

    reword m the program into a design document diregard the m 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 + b2 - 4ac 2a 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...

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

  • 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 a C programming code for the following prompt. please use stucture concept and test if...

    write a C programming code for the following prompt. please use stucture concept and test if the code works perfectly. Project Description: In this project, you will write a program to calculate the roots of a quadratic equation. Structure concepts will be used in this project. Your program will prompt the user to enter the coefficients of a quadra coefficientsType. Then it will compute the roots of the quadratic equation and store the result in a structure variable of type...

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

  • A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the...

    A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the above quadratic equation is computed using the following formula, root1 = (-b + sqrt(D))/ 2a root2 = (-b - sqrt(D))/2a Where D is the discriminant of the quadratic equation and is computed as, D = b^2 - 4ac Given the value of D, the roots of a quadratic equation can be categorized as follows, D > 0 : Two distinct real roots D =...

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

  • Plz help!! The programming language is C and could you write comments as well? Problem 2....

    Plz help!! The programming language is C and could you write comments as well? Problem 2. Calculate Grades (35 points) Arrays can be used for any data type, such as int and char. But they can also be used for complex data types like structs. Structs can be simple, containing simple data types, but they can also contain more complex data types, such as another struct. So you could have a struct inside of a struct. This problem deals with...

  • DQuestion 19 28 pts Problem 2. Quadratic Equations A quadratic equation has the form: a bc0 The two solutions are given by the formula: 2a Write a program with a loop that a) solves quadratic equatio...

    DQuestion 19 28 pts Problem 2. Quadratic Equations A quadratic equation has the form: a bc0 The two solutions are given by the formula: 2a Write a program with a loop that a) solves quadratic equations with coefficients read from the terminal, b) visualizes the corresponding quadratic function az2 brc0using the matplotlib module. Instructions Write all code for this problem in a file p2.py 1. The program consists of a main whtle loop (an infinite loop) in which the user...

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