/* * This program computes the volume of a sphere * Input: The radius of the sphere. * Output: The volume of the sphere. * */ #include #include Class Sphere { public: void set_radius(double rad); void compute_volume(); void print_volume(); private: double radius; double volume; } Sphere::set_radius(double rad) { const double Pi = 3.14159; // Mathematical constant radius = rad; compute_volume(); } Sphere::compute_volume() { volume = 4.0 * Pi * pow(radius, 3.0) / 3.0; } Sphere::print_volume() { cout << "\nvolume = " << volume << "\n\n"; } int main(void) { Class Sphere sphere; double radius; cout << "\n Please enter the radius of the sphere:"; cin >> radius; sphere.set_radius(radius); sphere.print_volume(); exit(0); }