|
|
 |
|
|
|
|
cout << A is too large. << endl;
b = 3;
}
else
cout << A is too small. << endl;
cout << All done. << endl; |
|
|
|
|
|
|
|
|
10. Given the float variables x1, x2, y1, y2, and m, write a program segment to find the slope of a line through the points (x1, y1) and (x2, y2). Use the formula |
|
|
|
 |
|
|
|
|
to determine the slope of the line. If x1 equals x2, the line is vertical and the slope is undefined. The segment should write the slope with an appropriate label. If the slope is undefined, it should write the message Slope undefined. |
|
|
|
|
|
|
|
|
11. Given the float variables a, b, c, root1, root2, and discriminant, write a program segment to determine whether the roots of a quadratic polynomial are real or complex (imaginary). If the roots are real, find them and assign them to root1 and root2. If they are complex, write the message No real roots. The formula for the solution to the quadratic equation is |
|
|
|
 |
|
|
|
|
The ± means plus or minus and indicates that there are two solutions to the equation: one in which the result of the square root is added to -b and one in which the result is subtracted from -b. The roots are real if the discriminant (the quantity under the square root sign) is not negative. |
|
|
|
|
|
|
|
|
12. Continue to validate the data in the lumberyard case study. Test for negative numeric values. Also check for invalid plywood thicknesses. Valid thicknesses are ¼, 3/8, ½, 5/8, ¾, 7/8, 4/4, 9/8, and 5/4. |
|
|
|
|
|
|
|
|
13. The following program reads data from an input file without checking to see if the file was opened successfully. Insert statements that will print an error message and terminate the program if the file cannot be opened. |
|
|
|
 |
|
|
|
|
include <iostream.h>
#include <fstream.h> // For file I/O
int main()
{
int m;
int n;
if stream info;
|
|
|
|
|
|