#include <iostream>
#include <cmath>
using namespace std;
void volume_square();//立方体体积函数声明
void volume_cylinder();//圆柱体积函数声明
void volume_cone();//圆锥体积函数声明
int main()
{
int choice=-1;
cout<<"请您选择需要计算体积的空间类型:"<<endl;
/*进行程序的循环*/
while(choice)
{
/*输出选项*/
cout<<"1:长方体"<<endl;
cout<<"2:圆柱体"<<endl;
cout<<"3:圆锥体"<<endl;
cout<<"0:结束程序"<<endl;
/*输入选项*/
cin>>choice;
/*选择要使用的功能*/
switch(choice)
{
case 1:volume_square();break;
case 2:volume_cylinder();break;
case 3:volume_cone();break;
case 0: cout<<"感谢使用!"<<endl;break;
}
}
return 0;
}
/*立方体体积函数*/
void volume_square()
{
double len,width,height;
cout<<"请输入长方体的长宽高:";
cin>>len>>width>>height;
double v=len*width*height;
cout<<"长方体的体积为:"<<v<<endl;
}
/*圆柱体体积函数*/
void volume_cylinder()
{
double radius,height;
cout<<"请输入圆柱体的底半径和高:";
cin>>radius>>height;
double v=3.14*pow(radius,2)*height;
cout<<"圆柱体的体积为:"<<v<<endl;
}
/*圆锥体体积函数*/
void volume_cone()
{
double radius,height;
cout<<"请输入圆锥体的底半径和高:";
cin>>radius>>height;
double v=(1.0/3.0)*3.14*pow(radius,2)*height;
cout<<"圆锥体的体积为:"<<v<<endl;
}
计算立方体、圆柱、圆锥体积的小程序
最新推荐文章于 2023-09-17 00:25:23 发布