/* (程序头部注释开始)
* 程序的版权和版本声明部分
* 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;
}