/* Sphere.cpp defines the nontrivial methods of class Sphere.
 * ... other documentation omitted
 *******************************************************************/

#include "Sphere.h"      // our Sphere class

void Sphere::setRadiusAndDensity(double radius, double density)
{
   if (radius > 0 && density > 0)    // validate arguments
   {                                 // update attributes
      myWeight = density * 4.0 * PI * pow(radius, 3) / 3.0;
      myRadius = radius;
      myDensity = density;
   }
   else
   {
      cerr << "setRadiusAndDensity(r, d): invalid arguments "
           << " r = " << radius << ", d = " << density;
      myRadius = myDensity = myWeight = 0.0;
   }
}

// ... other Sphere mutators left as exercises ...

void Sphere::readRadiusAndDensity(istream& in)
{
   double newRadius, newDensity;
   in >> newRadius >> newDensity;          // read inputs from in

   if (newRadius > 0 && newDensity > 0)    // validate inputs
   {                                       // update attributes
      myWeight = newDensity * 4.0 * PI * pow(newRadius, 3) / 3.0;
      myRadius = newRadius;
      myDensity = newDensity;
   }
   else
   {
      cerr << "readRadiusAndDensity(in): invalid input values "
           << " r = " << newRadius << ", d = " << newDensity;
      myRadius = myDensity = myWeight = 0.0;
   }
}
