#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
//the volume and surface area of sphere
struct sphere_t { float radius; };
sphere_t sph;
sph.radius = 3; // this is the part that mess me up, error in sph.radius
double SphereSurfaceArea(const sphere_t &sph)
{
return 4*M_PI*sph.radius*sph.radius;
}
double SphereVolume(const sphere_t &sph)
{
return 4.0/3.0*M_PI*sph.radius*sph.radius*sph.radius;
}
int main()
{
cout << "Sphere's description: " << sph.radius << endl;
cout << "Surface Area: " << SphereSurfaceArea(sph) << endl;
cout << "Volume :" <<SphereVolume(sph) << endl;
system("pause");
return(0);
}
我得到的输出是:
固体的描述 表面积 体积
如何通过常量引用将数字放入 const 函数并将函数设置为 void 而不返回任何内容?