C++ 计算几何的体积

C++ 计算几何的体积

#include <iostream>
#include <cmath>
using namespace std;

void V_Cuboid();	//计算长方体的体积
void V_Cyblinder();	//计算圆柱体的体积
void V_Cone();		//计算圆锥体的体积

void V_Cuboid()
{
	//输入长宽高
	double length, width, height;
	cout << "请输入长宽高:";
	cin >> length >> width >> height;
	//计算体积
	double v = length * width * height;
	//结果保留两位小数
	cout.setf(ios::fixed);
	cout << setprecision(2);
	//cout<<fixed<<setprecision(2);
	
	cout << "长方体的体积为:" << v << endl;
}

void V_Cyblinder()
{
	//输入半径、高
	const double pi = 3.14;
	double radius, height;
	cout << "请输入半径、高:";
	cin >> radius >> height;
	//计算体积
	double v = pi * pow(radius,2) * height;
	//结果保留两位小数
	cout.setf(ios::fixed);
	cout << setprecision(2);
	//cout<<fixed<<setprecision(2);
	
	cout << "长方体的体积为:" << v << endl;
}

void V_Cone()
{
	//输入半径、高
	const double pi = 3.14;
	double radius, height;
	cout << "请输入半径、高:";
	cin >> radius >> height;
	//计算体积
	double v = pi * pow(radius, 2) * height * 1/3;
	//结果保留两位小数
	cout.setf(ios::fixed);
	cout << setprecision(2);
	//cout<<fixed<<setprecision(2);
	
	cout << "圆锥体的体积为:" << v << endl;
}



int main() {
	int choice = -1;

	while(choice){
		cout << "1. 长方体" << endl;
		cout << "2. 圆柱体" << endl;
		cout << "3. 圆锥体" << endl;
		cout << "0. 退出" << endl;
		cin >> choice;
		switch (choice) {
		case 1:
			V_Cuboid();
			break;
		case 2:
			V_Cyblinder();
			break;
		case 3:
			V_Cone();
			break;
		}
	}
	cout << "感谢使用!" << endl;
	
	return 0;
}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值