#include #include double hypotenuse (double a, double b) { return sqrt ((a * a) + (b * b)); } double triangle_area (double height, double base) { return (height * base) / 2; } double roof_area (double length, double width, double height) { double l_side_area, w_side_area; // work out area of triangle having base of length "length" l_side_area = triangle_area (length, hypotenuse (height, width / 2)); // work out area of triangle having base of length 'w' w_side_area = triangle_area (width, hypotenuse (height, length / 2)); // compute and return total area of the roof return (2 * l_side_area) + (2 * w_side_area); } double ridge_length (double length, double width, double height) { return 4 * hypotenuse (hypotenuse (length, width) / 2, height); } bool dimensions_valid (double length, double width, double height) { return (length >= 10) && (width >= 10) && (height >= 0) && ((length/width) <= 4) && ((width/length) <= 4) && (height <= (2 * width)) && (height <= (2 * length)); } void main (void) { double length, width, height; for (;;) { // prompt user for and read the input quamtities cout << endl // space before prompt << "Please enter roof length, width and height (zeroes to exit): "; cin >> length >> width >> height; if ((length == 0) && (width == 0) && (height == 0)) { return; } if (dimensions_valid(length, width, height)) { cout << endl << "The area of the roof is " << roof_area (length, width, height) << " square units." << endl << "The roof requites " << ridge_length (length, width, height) << " linear units of capping." << endl; } else { cout << "Those values are invalid - no computations performed." << endl; } } // end for (;;) }