Tuesday, July 14, 2009

Help with c++ assignment?

ok, here is the assignment my comp sci teacher gave me:





2. The roots of the quadratic equation ax2 + bx + c = 0, where a, b, %26amp; c are real numbers, and a ≠ 0, are given by the following formula:





http://www.people.iup.edu/ykwl/





In this formula the term b2-4ac is called the discriminant. If b2 - 4ac = 0, so the equation has a single repeated root. If b2 - 4ac %26gt; 0, the equation has two real roots. If b2-4ac %26lt; 0, the equation has two complex roots. Write a program that reads the following values [{1, 3, 1}, {1, 2, 1}, {2, 1, 1}] from the keyboard and assign them to the three sets of coefficients [{a1, b1, c1}, {a2, b2, c2}, {a3, b3, c3}]. The program then outputs the type of the roots of the equation for each set. Furthermore, if b2 - 4ac ≥ 0, the program should output the root(s) of the quadratic equation.





So, i dont understand when he says the "root of the equation". Can someone help me uderstand what i am suspose to do and how i would star off the program?

Help with c++ assignment?
The root of the equation is where the y is zero.





Get the values:





double a1, b1, c1;


cin %26gt;%26gt; a1 %26gt;%26gt; b1 %26gt;%26gt; c1;





Calculate the discriminant and test it:





double d1 = b1 * b1 - 4 * a1 * c1;


if (d1 %26lt; 0)


cout %26lt;%26lt; "Two complex roots" %26lt;%26lt; endl;


else if (d1 %26gt; 0)


cout %26lt;%26lt; "Two real roots: " %26lt;%26lt; ( -b1 + sqrt( d1 ) ) / ( 2 * a1 ) %26lt;%26lt; " and " %26lt;%26lt; ( -b1 - sqrt( d1 ) ) / ( 2 * a1 ) %26lt;%26lt; endl;


else // d1 == 0


cout %26lt;%26lt; "One real root: " %26lt;%26lt; -b1 / ( 2 * a1 ) %26lt;%26lt; endl;
Reply:If b2-4ac =0 then b2-4ac =1,3,1 of complex 1


Then complex 2 which is = to -4ac (Root of 2,1)kb config


Root of the equation means u will have to find the root of b2-4ac





that's it!


No comments:

Post a Comment