Inline function that calculates the volume of a sphere : inline « Class « C++






Inline function that calculates the volume of a sphere

  
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

#include <cmath>

const double PI = 3.14159;

inline double sphereVolume( const double r ) 
{ return 4.0 / 3.0 * PI * pow( r, 3 ); }

int main()
{
   double radius;

   cout << "Enter the length of the radius of your sphere: ";
   cin >> radius;
   cout << "Volume of sphere with radius " << radius << 
           " is " << sphereVolume( radius ) << endl;
   return 0;
}
  
    
  








Related examples in the same category

1.Inline functions may be class member functionsInline functions may be class member functions
2.Automatic inlineAutomatic inline
3.Create an inline function.Create an inline function.
4.Use inline to make this program more efficient
5.Creating Inline Functions Inside a Class