#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
struct sphere_t { float radius; }; sphere_t sph = { 5.8 };
void SphereDescription(sphere_t &sph) { cout << "Sphere's
description: "; cin >> 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; }
//the volume and surface area of cylinder
struct cylinder_t { float
radius ; float height ; }; cylinder_t cylr,cylh = { 6.6,1.3 };
double SurfaceAreaCylinder(const cylinder_t &cylr,const cylinder_t&cylh)
{ return (2*M_PI*cylr.radius)*2 +2*M_PI*cylr.radius*cylh.height; }
double CylinderVolume(const cylinder_t &cylr,const cylinder_t &cylh) { return 2*M_PI*cylr.radius*cylr.radius*cylh.height; }
int main() { cout << "Sphere's description radius: " << sph.radius << endl; cout << "Surface Area: " << SphereSurfaceArea(sph) << endl; cout << "Volume :" << SphereVolume(sph) << endl;
cout << "Cylinder's description radius: " << cylr.radius << endl; cout << "Cylinder's description height: " << cylh.height << endl; cout << "Surface Area: " << SurfaceAreaCylinder(cylr,cylh) << endl; cout << "Volume :" << CylinderVolume(cylr,cylh) << endl;
system("pause"); return(0); }
//输出
Sphere's description radius: 5.8
Surface Area: 422.733
Volume : 817.283
Cylinder's description radius: 0
Cylinder's description height: 1.3
Surface Area: 0
Volume : 0
为什么半径、SA 和体积处的输出为零?