Answer:
#include <cmath>
#include <iostream>
using namespace std;
int getSphereSize(double length, double breadth, double height) {
double diagonal = sqrt(length * length + breadth * breadth + height * height);
if (diagonal <= 4)
return 4;
if (diagonal <= 6)
return 6;
if (diagonal <= 8)
return 8;
if (diagonal <= 10)
return 10;
if (diagonal <= 12)
return 12;
return 0;
}
int main() {
double length, breadth, height;
int sphereCounts[5] = {0};
int sphereSize;
while (true)
cout << "\\Number of 4-inch spheres: " << sphereCounts[0];
cout << "\\Number of 6-inch spheres: " << sphereCounts[1];
cout << "\\Number of 8-inch spheres: " << sphereCounts[2];
cout << "\\Number of 10-inch spheres: " << sphereCounts[3];
cout << "\\Number of 12-inch spheres: " << sphereCounts[4];
cout << endl;
return 0;
}
Step-by-step explanation:
The "cmath" library is included in the c++ program. The getSphereSize function is used to return the sphere size the rectangle dimension can fit into. It program continuously prompts the user for the length, breadth, and height of the rectangle and passes the values to the getSphereSize function in the while but breaks if any or all of the variable value is zero.
The sizes of the sphere objects in inches are collected in an array of five integer values of zeros and are incremented by one for every match with a rectangle.