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

📄 ex18_04.cpp

📁 C程序设计经典教程第5版程序示例,比较适合初级c语言的学生
💻 CPP
字号:
// Exercise 18.4 Solution: Ex18_04.cpp
// Inline function that calculates the volume of a sphere.
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

#include <cmath>
using std::pow;

const double PI = 3.14159; // define global constant PI

// calculates volume of a sphere
inline double sphereVolume( const double radius ) 
{ 
   return 4.0 / 3.0 * PI * pow( radius, 3 ); 
} // end inline function sphereVolume

int main()
{
   double radiusValue;

   // prompt user for radius 
   cout << "Enter the length of the radius of your sphere: ";
   cin >> radiusValue; // input radius 

   // use radiusValue to calculate volume of sphere and display result
   cout << "Volume of sphere with radius " << radiusValue 
      << " is " << sphereVolume( radiusValue ) << endl;
   return 0; // indicates successful termination
} // end main

⌨️ 快捷键说明

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