实验内容
设置圆半径r=2.5,圆柱h=4,求圆的周长、圆面积、圆球体积、圆柱体积。用cin输入要计算的项目,输入输出均要有文字提示
#include <iostream>
#include <string.h>
using namespace std;
int main() {
const double PI = 3.14159265;
double r=2.5, h=4.0, dResult;
int nID;
while(1) {
cout<<"1-计算圆周长"<<endl;
cout<<"2-计算圆面积"<<endl;
cout<<"3-计算圆球体积"<<endl;
cout<<"4-计算圆柱体积"<<endl;
cout<<"5-退出"<<endl;
cout<<"请选择命令号1-5"<<endl;
cin>>nID;
if(nID == 5) break;
else {
switch(nID) {
case 1:
dResult = PI*r*2.0;
cout<<"圆周长为:"<<dResult<<endl;
break;
case 2:
dResult = PI*r*r;
cout<<"圆面积为:"<<dResult<<endl;
break;
case 3:
dResult = PI*r*r*r*4.0/3.0;
cout<<"圆球体积为:"<<dResult<<endl;
break;
case 4:
dResult = PI*r*r*h;
cout<<"圆柱体积为:"<<dResult<<endl;
break;
default:
cout<<"选择的命令号不对!"<<endl;
break;
}
cout<<"按Enter键继续……";
cin.get();
cin.get();
system("cls");
}
}
return 0;
}
实验结果
版权声明:本文为qq_33290233原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。