Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Topic: Chapter 4 (if and if / else if) Write a C++ program to solve for the real roots of quadratic equations. Submit the CPP

Topic: Chapter 4 (if and if / else if)

Write a C++ program to solve for the real roots of quadratic equations.

Submit the CPP file in Canvas

Quadratic equation:

For the equation ax2 + bx + c = 0, we can have 0, 1, 2 for the root x. Only real root is considered.

The discriminant value is b 4 a c

There are 3 possibilities:

* b 4ac > 0: there are 2 distinct roots

image text in transcribed

* b 4ac == 0: there is only one root

x = -b / 2a

* b 4ac

Computers do not understand concept of imaginary numbers.

See these links:

http://www.purplemath.com/modules/quadform3.htm#top

http://www.math.com/students/calculators/source/quadratic.htm

Requirements:

-Programs asks user to enter value of a b c on a single line separated by spaces. The value of a, b, c are floating-point numbers that may have decimal fractions.

- Print a user-friendly message if a coefficient value is 0 and do not perform any calculation:

Coefficient a cannot be 0.

-The results should have exactly 4 digits after the decimal point.

Sample run

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

- 6 62 - 4ac 2a This program solves a quadratic equation. Enter the coefficient a b c in this order separated by spaces: 5 3 2 There is no real root. Process returned 0 (0x0) Press any key to continue. execution time : 5.396 s This program solves a quadratic equation. Enter the coefficient a b c in this order separated by spaces: 2 8 1 There are two roots: -0.1292 and -3.8708 Process returned 0 (0x0)_ Press any key to continue. execution time : 5.132 si This program solves a quadratic equation. Enter the coefficient a b c in this order separated by spaces: 3 10 2 There are two roots: -0.2137 and -3.1196 Process returned 0 (0x0)_ Press any key to continue. execution time : 8.855 s This program solves a quadratic equation. Enter the coefficient a b c in this order separated by spaces: 1 2 1 There is one root: -1.0000 Process returned 0 (0x0)_ Press any key to continue. execution time : 3.494 si This program solves a quadratic equation. Enter the coefficient a b c in this order separated by spaces: 1.1 2.2 1.1 There is one root: -1.0000 Process returned 0 (0x0) Press any key to continue. execution time : 4.673 s This program solves a quadratic equation. Enter the coefficient a b c in this order separated by spaces: 2.4 2 There is one root: -1.0000 Process returned 0 (Ox0)_ Press any key to continue. execution time : 2.889 s This program solves a quadratic equation. Enter the coefficient a b c in this order separated by spaces: 012 Coefficient a cannot be 0 Process returned 1 (0x1)_ execution time : 5.674 s Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions