⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sphere.cpp

📁 Data Abstraction & Problem Solving with C++源码
💻 CPP
字号:
// *********************************************************// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -