第五周作业(三)
2014年01月08日
⁄ 综合
⁄ 共 722字 ⁄ 字号
小 中 大
-
#include <iostream>
-
using namespace std;
-
class Box
-
{
-
public:
-
Box();
-
Box(int h,int w,int l):height(h),width(w),length(l){};
-
int volume();
-
int area();
-
void input();
-
private:
-
int height;
-
int width;
-
int length;
-
};
-
-
int Box:: volume()
-
{
-
return(height*width*length);
-
}
-
int Box::area()
-
{
-
int s;
-
s=height*width+width*length+height*length;
-
return (2*s);
-
}
-
Box::Box()
-
{
-
height=10;
-
width=10;
-
length=10;
-
}
-
void Box::input()
-
{
-
cin>>height>>width>>length;
-
}
-
int main()
-
{
-
Box a[5]={
-
Box(10,12,15),
-
Box(15,18,20),
-
Box(16,20,26),
-
Box(),
-
Box()
-
};
-
cout<<"长方柱1的面积是:"<<a[0].area()<<'\t'<<"体积是:"<<a[0].volume()<<endl<<endl;
-
cout<<"长方柱2的面积是:"<<a[1].area()<<'\t'<<