长方柱类

来源:互联网 发布:网络大电影报批流程 编辑:程序博客网 时间:2024/05/18 10:16
#include <iostream>
using namespace std;
class Bulk
{
public:
    Bulk(double l=1,double w=1,double h=1)
    {
        length=l;
        width=w;
        height=h;
    }
    void get_value();
    void output();
private:
    double length;
    double width;
    double height;
};
void Bulk::get_value()
{
    double l,w,h;
    cin>>l>>w>>h;
    length=l;
    width=w;
    height=h;
}
void Bulk::output()
{
    cout<<"长方柱体积"<<length*width*height<<"长方柱表面积"<<2*length*width+2*length*height+2*width*height<<endl;
}
int main()
{
    int i;
    Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};
    b[4].get_value();
    for(i=0;i<5;i++)
        b[i].output();
}
0 0
原创粉丝点击