该计划的预期结果如下:
选择形状 (1) 球体 (2) 圆柱体 (3) 圆锥体 (q) 退出:1
选择计算 (1) 体积 (2) 表面积:1
输入球体半径:5.5
球体体积为 696.91
选择形状 (1) 球体 (2) 圆柱体 (3) 圆锥体 (q) 退出:1
选择计算 (1) 体积 (2) 表面积:2
输入球体半径:5.5 球体
表面积为 380.133
选择形状 (1) 球体 (2) 圆柱体 (3) 圆锥体 (q) 退出:2
选择计算 (1) 体积 (2) 表面积:1
输入圆柱体半径:5.5
输入圆柱体高度:4.2
圆柱体体积是 399.139
选择形状 (1) 球体 (2) 圆柱体 (3) 圆锥体 (q) 退出:2
选择计算 (1) 体积 (2) 表面积:2
输入圆柱体半径:5.5
输入圆柱体高度:4.2
表面积气缸是 335.208
选择形状 (1) 球体 (2) 圆柱体 (3) 圆锥体 (q) 退出:3
选择计算 (1) 体积 (2) 表面积:1
输入圆锥体半径:5.5
输入圆锥体高度:4.2
圆锥体体积是 133.046
选择形状 (1) 球体 (2) 圆柱体 (3) 圆锥体 (q) 退出:3
选择计算 (1) 体积 (2) 表面积:2
输入圆锥体半径:5.5
输入圆锥体高度:4.2
表面积圆锥是 214.607
选择形状 (1) 球体 (2) 圆柱体 (3) 圆锥体 (q) 退出:q
再见!
我想你可以知道我的前进方向......为什么我不能让我的循环正常工作?
#include <iostream>
#include <math.h>
using namespace std;
double sphere_volume(double radius);
double sphere_surface_area(double radius);
double cylinder_volume(double radius, double height);
double cylinder_surface_area(double radius, double height);
double cone_volume(double radius, double height);
double cone_surface_area(double radius, double height);
int main()
{
double entHeight;
double entRadius;
char shapeCall;
char compCall;
cout << "Select a Shape (1) sphere (2) cylinder (3) cone (q) quit: ";
cin >> shapeCall;
cout << "Select a Computation (1) volume (2) surface area: ";
cin >> compCall;
if ( shapeCall == 1 && compCall == 1)
{
cout << "Enter Radius: ";
cin >> entRadius;
cout << sphere_volume (entRadius) << endl;
}
if ( shapeCall == 1 && compCall == 2)
{
cout << "Enter Radius: ";
cin >> entRadius;
cout << sphere_surface_area (entRadius) << endl;
}
if ( shapeCall == 2 && compCall == 1)
{
cout << "Enter Radius: ";
cin >> entRadius;
cout << "Enter Height: ";
cin >> entHeight;
cout << cylinder_volume (entRadius, entHeight) << endl;
}
if (shapeCall == 2 && compCall == 2)
{
cout << "Enter Radius: ";
cin >> entRadius;
cout << "Enter Height: ";
cin >> entHeight;
cout << cylinder_surface_area (entRadius, entHeight) << endl;
}
if (shapeCall == 3 && compCall == 1)
{
cout << "Enter Radius: ";
cin >> entRadius;
cout << "Enter Height: ";
cin >> entHeight;
cout << cone_volume (entRadius, entHeight) << endl;
}
if (shapeCall == 3 && compCall == 2)
{
cout << "Enter Radius: ";
cin >> entRadius;
cout << "Enter Height: ";
cin >> entHeight;
cout << cone_surface_area (entRadius, entHeight) << endl;
}
system ("pause");
return 0;
}
double sphere_Volume(double radius)
{
return 4.0 / 3.0 * 3.14159 * pow( radius, 3 );
}
double cylinder_volume(double radius, double height)
{
return 3.14159 * pow(radius, 2) * height;
}
double cone_volume(double radius, double height)
{
return 1.0 / 3.0 * 3.14159 * pow(radius, 2) * height;
}
double sphere_surface_area(double radius)
{
return 4.0 * 3.14159 * pow(radius, 2);
}
double cylinder_surface_area(double radius, double height)
{
return (2.0 * 3.14159 * pow(radius, 2)) + (2.0 * 3.14159 * radius * height);
}
double cone_surface_area(double radius, double height)
{
return (3.14159 * pow(radius, 2)) + (3.14159 * radius * sqrt(pow(radius, 2) + pow(height, 2)));
}