#include #include #include void pause () { cout << "\nHit any key to continue....\n"; getch (); } struct point { double z, y; }; struct rectangle { double z_size, y_size; double area; point centre; }; double square (double x) { return x * x; } double cube (double x) { return x * x * x; } // function "calculate_moments" goes in here int main () { const int max_rectangles = 40; rectangle rectangles[max_rectangles]; double Iz, Iy, Iyz; int n = 0; // number of rectangles point centroid; for (;;) { cout << "\nEnter z and y size of rectangle (0, 0 to quit): "; cin >> rectangles[n].z_size >> rectangles[n].y_size; if ((rectangles[n].z_size <= 0) || (rectangles[n].y_size <= 0)) { break; } // compute area rectangles[n].area = rectangles[n].z_size * rectangles[n].y_size; cout << "Enter z and y co-ordinates of rectangle centre: "; cin >> rectangles[n].centre.z >> rectangles[n].centre.y; ; if (++n == max_rectangles) { cout << "\n** Max nember of rectangles reached. **\n"; break; } } // do the calculations calculate_moments (rectangles, n, centroid, Iz, Iy, Iyz); // output the results cout << "\nCentroid z = " << centroid.z << " Centroid y = " << centroid.y << endl << "\nIz = " << Iz << " Iy = " << Iy << " Iyz = " << Iyz << endl; pause (); return 0; }