sphere.cpp

来自「Data Abstraction & Problem Solving with 」· C++ 代码 · 共 62 行

CPP
62
字号
// *********************************************************// Implementation file Sphere.cpp for the class Sphere.// *********************************************************#include "Sphere.h"   // header file#include <iostream.h>Sphere::Sphere(): theRadius(1.0){}  // end default constructorSphere::Sphere(double initialRadius){   if (initialRadius > 0)      theRadius = initialRadius;   else      theRadius = 1.0;}  // end constructorvoid Sphere::setRadius(double newRadius){   if (newRadius> 0)      theRadius = newRadius;   else      theRadius = 1.0;}  // end setRadiusdouble Sphere::getRadius() const{   return theRadius;}  // end getRadiusdouble Sphere::getDiameter() const{   return 2.0 * theRadius;}  // end getDiameterdouble Sphere::getCircumference() const{   return PI * getDiameter();}  // end getCircumferencedouble Sphere::getArea() const{   return 4.0 * PI * theRadius * theRadius;}  // end getAreadouble Sphere::getVolume() const{   double radiusCubed = theRadius * theRadius * theRadius;    return (4.0 * PI * radiusCubed)/3.0;}  // end getVolumevoid Sphere::displayStatistics() const{   cout << "\nRadius = " << getRadius()        << "\nDiameter = " << getDiameter()        << "\nCircumference = " << getCircumference()        << "\nArea = " << getArea()        << "\nVolume = " << getVolume() << endl;}  // end displayStatistics// End of implementation file.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?