C++ Class Definition Sphere class with member functions added

Description

C++ Class Definition Sphere class with member functions added

#include  <math.h>
const float PI = 3.14159;
// A sphere class.
class Sphere//from  w  w  w  . j a  v  a2  s .com
{
   public:
   float r;        // Radius of sphere
   float x, y, z;  // Coordinates of sphere
   Sphere(float xcoord, float ycoord, float zcoord, float radius)
   {
      x = xcoord; y = ycoord; z = zcoord; r = radius;
   }
   ~Sphere() { }
   float volume()
   {
      return (r * r * r * 4 * PI / 3);
   }
   float surface_area()
   {
      return (r * r * 4 * PI);
   }
};



PreviousNext

Related