【c++练习】求3个长方柱的体积

【问题描述】编写一个基于对象数组的程序,用成员函数实现多个功能,求3个长方柱的体积。要求用成员函数实现以下功能:

1、由键盘分别输入3个长方柱的长、宽、高;

2、计算长方柱的体积;

3、输出3个长方柱的体积。

【输入形式】用户由键盘分别输入3个长方柱的长、宽、高。

【输出形式】输出3个长方柱的体积。

【样例输入】

10 10 10

12 13 14

15 2 34

【样例输出】

Please input length,width and height:

The volume is:1000

Please input length,width and height:

The volume is:2184

Please input length,width and height:

The volume is:1020

【样例说明】用户根据提示由键盘分别输入3个长方柱的长、宽、高。依次输出3个长方柱的体积。

【评分标准】 结果完全正确得10分,每个测试点5分。提交程序名为:hanxin.c或hanxin.cpp

#include<iostream>
using namespace std;

class cuboid
{
	public:
	int chang;
	int kuan;
	int gao;
	int v;
	
	public:
		void set_cuboid()
		{
			cin>>chang>>kuan>>gao;
		}
		int volume(int chang,int kuan,int gao)
		{
			v=chang*kuan*gao;
			return v;
		}
	
};

int main()
{
	for(int i=0;i<3;i++)
	{
		cuboid c1;
		cout<<"Please input length,width and height:"<<endl;
		c1.set_cuboid();
		int res=c1.volume(c1.chang,c1.kuan,c1.gao);
		cout<<"The volume is:"<<res<<endl;
	}
	return 0;
 } 

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值