![]() |
Data Abstraction and Problem Solving with C++Walls and Mirrorsby Frank M. Carrano |
![]() |
Sphere406.cppGo to the documentation of this file.00001 #include <iostream> 00002 #include "Sphere406.h" 00003 00004 using namespace std; 00005 00006 Sphere::Sphere() : theRadius(1.0) 00007 { 00008 } 00009 00010 Sphere::Sphere(double initialRadius) : theRadius(initialRadius) 00011 { 00012 } 00013 00014 void Sphere::setRadius(double newRadius) 00015 { 00016 if (newRadius > 0) 00017 theRadius = newRadius; 00018 } 00019 00020 double Sphere::getRadius() const 00021 { 00022 return theRadius; 00023 } 00024 00025 double Sphere::getDiameter() const 00026 { 00027 return 2 * theRadius; 00028 } 00029 00030 double Sphere::getCircumference() const 00031 { 00032 return PI * getDiameter(); 00033 } 00034 00035 double Sphere::getArea() const 00036 { 00037 return 4.0 * PI * theRadius * theRadius; 00038 } 00039 00040 double Sphere::getVolume() const 00041 { 00042 return 4.0 / 3.0 * getArea() * theRadius; 00043 } 00044 00045 void Sphere::displayStatistics() const 00046 { 00047 cout << "\nRadius = " << getRadius() 00048 << "\nDiameter = " << getDiameter() 00049 << "\nCircumference = " << getCircumference() 00050 << "\nArea = " << getArea() 00051 << "\nVolume = " << getVolume() << endl; 00052 } |