Question: Write a program in C++ 1. When floating point numbers (i.e. float) are added in C/C++, round-off errors can occur if the numbers differ by
Write a program in C++
1. When floating point numbers (i.e. float) are added in C/C++, round-off errors can occur if the numbers differ by more than 7 significant digits. Recall that the roots of the quadratic equation ax2 + bx+c=0 root1 = -b+d root2 = bad where d=b2 - 4ac 2a 9 are real if and only if 62 - 4ac >=0. To illustrate round-off problems, write a program that computes the roots of a quadratic equation. The program reads coefficients a, b, and c from the keyboard, checks the existence of real roots, computes the roots using the above formula if real roots exits, and prints the roots to the screen, otherwise it prints a message to the screen stating that no real roots exist. Here are three sample inputs/ouputs: Enter the three coefficients: 1-5 6 a = 1.000000, b = -5.000000, c = 6.000000 root1 = 3.000000 root2 = 2.000000 Enter the three coefficients: 1 2 3 a = 1.000000, b = 2.000000, c = 3.000000 No real roots found Enter the three coefficients: 1.0 - 10.0001 25.0005 a = 1.000000, b = -10.000100, c = 25.000500 root1 5.001431 root2 = 4.998669 In case 3, there will be precision problems and the estimated roots will be near but not equal to the true roots of 5.0000 and 5.0001
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
