/* Project 2 driver * * Name: Paul Hatalsky * Instructor: P. Hatalsky * Section: 19 * * This file contains the drive code for Program 2, massCalculator.c */ #include <stdio.h> /* Function Prototypes */ double volumeOfBox(double l, double w, double h); double volumeOfSphere(double r); int boxContainsSphere(double l, double w, double h, double r); int sphereContainsBox(double l, double w, double h, double r); double getDouble(); void printVolSolids(double volBox, double volSphere); void printMassSolids(double massBox, double massSphere); void printMassVoids(double massBoxVoid, double massSphereVoid); int main(void) { double length, width, height, radius, density; double volBox, volSphere; double massBoxWithVoid = 0, massSphereWithVoid = 0; /* Input the dimensions of the box */ printf("Enter the dimensions in inches of a rectilinear box...\n"); printf(" Length: "); length = getDouble(); printf(" Width : "); width = getDouble(); printf(" Height: "); height = getDouble(); /* Input the radius of the shpere */ printf("\nEnter the dimensions in inches of a sphere...\n"); printf(" Radius: "); radius = getDouble(); /* Input the density */ printf("\nEnter the material density in pounds per cubic inch...\n"); printf(" Density: "); density = getDouble(); /* Calculate the volumes */ volBox = volumeOfBox(length, width, height); volSphere = volumeOfSphere(radius); /* Print the volumes and masses of the solid shapes */ printVolSolids(volBox, volSphere); printMassSolids(volBox * density, volSphere * density); /* Calculate masses of the hollow shapes if one shape fits in the other */ if (boxContainsSphere(length, width, height, radius)) { massBoxWithVoid = density*(volBox - volSphere); } else if (sphereContainsBox(length, width, height, radius)) { massSphereWithVoid = density*(volSphere - volBox); } /* Print the masses of the hollow shapes */ printMassVoids(massBoxWithVoid, massSphereWithVoid); return 0; }