Saturday, May 22, 2010

Please help write c++ program to decide if the coefficients of a quadratic equation have real roots.?

write a C++ program to decide if the coefficients of a quadratic equation have real roots. The three choices will be to write the message “zero divide” when A is zero, write the message “no real roots” if the discriminant is negative and find the two roots when there is no error condition. DO NOT FIND THE ROOT IF THERE IS AN ERROR CONDITION.


use a NESTED DECISION to do the three parts of the algorithm above.


write a sentinel-controlled loop based on a character value to control the loop, q or Q will terminate the loop, any other value will continue processing. Read the value from the keyboard and write to the monitor. Use the inputs given below.


4. document the program properly, Use format for both the roots. Be sure to set the iosflags, setprecision, and showpoint. Use a setprecision of 3. also use setw for each numeric output.


libraries needed: iostream, cmath, iomanip. Add the .h, math.h for other compilers.

Please help write c++ program to decide if the coefficients of a quadratic equation have real roots.?
All you need to do is check the value of b^2 - 4ac. I leave precision, input/output, formatting for C++, etc. etc. to you. This is just the basic conditional statement that will be the heart of your program.





if (a = 0) {


zero divide


}


else if (b^2 - 4ac %26lt; 0) {


if (b != 0) {


imaginary


}


else {


complex


}


}


else {


real


}
Reply:if you are looking for the formulas:





zero - of course check the value of A,





discriminant = b^2 - 4ac and if the answer is 0 there is 1 root, if the answer is negative there are no real roots, and if the answer is positive there will be 2 real roots.





The formula for the real roots:





(- b + sqrt (b^2 - 4ac)) / 2 , and (- b - sqrt (b^2 - 4ac)) / 2


No comments:

Post a Comment