第五周任务3

#include<iostream>

using namespace std;

class Box
{
public:
	Box(float h = 10, float w = 12, float len = 15) : heigth(h), width(w), length(len){};//声明有默认参数的构造函数,用参数初始化表对数据成员初始化
    int volume();
	int area();
	void input();
private:
	float heigth;
    float width;
    float length;
};

int Box :: volume()
{
	return (heigth * width * length);
}

int Box :: area()
{
	return ((heigth * width + heigth * length + width * length) * 2);
}


void Box :: input()
{
	cout << "请输入长方柱的长,宽,高:";
	cin >> length >> width >> heigth;
}

int main()
{
	Box a[5] = {
	Box(6, 7, 8),
	Box(15, 18, 20),
	Box(16, 20, 26),
	Box(),
	Box()
	};
	for(int i = 0; i < 5; ++i)
	{
		if(i == 4)a[4].input();
		cout << "第" << i + 1 << "长方柱类的体积是    " << a[i].volume() << endl;
	    cout << "第" << i + 1 << "长方柱类的表面积是  " << a[i].area() << endl << endl;
	}

	return 0;

}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值