第五周实验三

来源:互联网 发布:mac版steam怎么安装 编辑:程序博客网 时间:2024/05/01 13:11
#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;   }    

 
原创粉丝点击