第五周任务三 长方体

 

/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称: class Box                            
* 作    者:      姜雅明                       
* 完成日期:     2012    年   03    月    19    日
* 版 本 号:       1.0  

* 对任务及求解方法的描述部分
* 输入描述: 长方体的长,宽,高
* 问题描述: 计算长方体的面积和体积
* 程序输出: 长方体的长,宽,高,体积,面积
* 程序头部的注释结束
*/

#include <iostream>

using namespace std;

class Box
{
public:
	Box(int h = 3, int w = 4, int l = 5):height(h),width(w),length(l){}
	int volume();
	int area();
	void input();
	void output();

private:
	int height; int width; int length;
};
void main()
{
	Box a[5]={Box(10,12,15), Box(15,18,20), Box(16,20,26), Box(), Box()};

	a[0].output(); 
	a[1].output();  
	a[2].output(); 
	a[3].output();  
    
	a[4].input();
	a[4].output();  
}


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

int Box:: area()
{
	int i;

	i = (height * width + height * length + width * length) * 2;

	return i;
}

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

void Box:: output()
{
	cout << "长为" << length << "宽为" << width << "高为" << height << "的长方体";
	cout << "体积:" << volume( ) << "  表面积:" << area() << endl <<endl;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值