- #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'<<"体积是:"<<a[1].volume()<<endl<<endl;
- cout<<"长方柱3的面积是:"<<a[2].area()<<'\t'<<"体积是:"<<a[2].volume()<<endl<<endl;
- cout<<"长方柱4的面积是:"<<a[3].area()<<'\t'<<"体积是:"<<a[3].volume()<<endl<<endl;
- cout<<"请输入长方柱5的长,宽,高:";
- a[4].input();
- cout<<endl;
- cout<<"长方柱5的面积是:"<<a[4].area()<<'\t'<<"体积是:"<<a[4].volume()<<endl<<endl;
- return 0;
- }
第五周作业(三)
最新推荐文章于 2023-04-08 09:39:53 发布