// ************************************************************** // Implementation file sphereClass.cpp for the class sphereClass. // ************************************************************** #include #include "sphereClass.h" // header file using namespace std; sphereClass::sphereClass() { theRadius = 1.0; } // end default constructor sphereClass::sphereClass(double initialRadius) { theRadius = (initialRadius>0) ? initialRadius : 1.0; } // end constructor void sphereClass::SetRadius(double newRadius) { theRadius = (newRadius>0) ? newRadius : theRadius; } double sphereClass::Radius() const { return theRadius; } double sphereClass::Diameter() const { return 2.0 * theRadius; } double sphereClass::Circumference() const { return PI * Diameter(); } double sphereClass::Area() const { return 4.0 * PI * (theRadius * theRadius); } double sphereClass::Volume() const { double radiusCubed = theRadius * theRadius * theRadius; return (4.0 * PI * radiusCubed)/3.0; } void sphereClass::DisplayStatistics() const { cout << "\nRadius = " << Radius() << "\nDiameter = " << Diameter() << "\nCircumference = " << Circumference() << "\nArea = " << Area() << "\nVolume = " << Volume() << endl; } // End of implementation file.