#include<iostream>
using namespace std;
class Box
{
public:
Box();
Box(int,int,int);
int volume();
int area();
void lwh();
private:
int length;
int width;
int heigth;
};
Box::Box(int h,int w,int len)
{
width=w;
heigth=h;
length=len;
}
Box::Box()
{
length=10;
width=10;
heigth=10;
}
int Box::volume()
{
return (length*width*heigth);
}
int Box::area()
{
return (2*(length*width+length*heigth+width*heigth));
}
void Box::lwh()
{
cout<<"请输入该三角形的长,宽,高:";
cin>>length>>width>>heigth;
}
void main()
{
Box a[5]=
{
Box(11,12,13),
Box(2,4,6),
Box(16,15,14)
};
for(int i=0;i<4;i++)
{
cout<<"第"<<i+1<<"个长方柱的体积为:"<<a[i].volume()<<endl<<" 长方柱的表面积为:"<<a[i].area()<<endl;
}
Box b1;
a[4].lwh(); cout<<"第"<<i+1<<"个长方柱的体积为:"<<a[i].volume()<<endl<<" 长方柱的表面积为:"<<a[i].area()<<endl;
}
第五周实验三
最新推荐文章于 2022-04-11 21:44:53 发布