Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this program you are to write a simple function to find the roots of quadratic equations. The function proto type should be: int roots(double,

For this program you are to write a simple function to find the roots of quadratic equations. The function proto type should be: int roots(double, double, double, double &, double &, double &, double &); the first three parameters should be the coefficients of the quadratic polynomial. The first, the x 2 coefficient, should be non-zero, in this case roots should return 1, if the x 2 coefficient is zero roots should return 0. If the x 2 coefficient is non-zero the roots should be returned in the last four reference parameters. The forth parameter should contain the real part, and the fifth the imaginary part of one solution. The sixth the real and the seventh the imiginary part of the other root. If the x 2 coefficient is zero the last four parameters should not have their values changed. In addition there should be no output satatments in your function roots. Notice that to test your function, you will also need to write a main() function to call the roots function with the appropriate parameters. If the x 2 coefficient is zero, your program should output that the equation is not quadratic, otherwise your program should output the two roots. Also you may wish to use the sqrt() function, in this case you may need to inculde the cmath header file. 1 Solving a Quadratic Equation. If a 6= 0 the equation ax2 + bx + c = 0 has 2 solutions given by x = b b 2 4ac 2a and x = b + b 2 4ac 2a . The quantity b 2 4ac is called the discriminant. If b 2 4ac = 0 then the two separate solutions become the same and there is only one solution. If b 2 4ac < 0 then the two solutions are complex numbers. In this case both solutions have the same real part, that is b 2a and the imaginary parts are 4acb 2 2a and 4acb 2 2a . Notice also that a real number is a complex number with the imaginary part equal to zero. Test data for you program 2x 2 + 10x + 1 = 0 x 2 1 = 0 x 2 2x + 1 = 0 5x 2 + 1x + 7 = 0 3x + 5 = 0

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

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions