第四周项目3 用对象数组操作长方柱类

来源:互联网 发布:蓝牙模块设置软件 编辑:程序博客网 时间:2024/06/05 01:41
/**Copyright (c) 2014, 烟台大学计算机学院*All rights reserved.*文件名称:test.cpp*作者:于凯*完成日期:2015年4月6日*版本号:v1.0*/#include <iostream>using namespace std;class Bulk{public:    Bulk(double x=1.0,double y=1.0,double z=1.0):lengh(x),width(y),height(z) {};    void get_value();    void display();private:    double lengh;    double width;    double height;};void Bulk::get_value(){    cout<<"请顺序输入长、宽、高:";    cin>>lengh>>width>>height;}void Bulk::display(){    cout<<"体积是: "<<lengh*width*height<<endl;    cout<<"表面积是: "<<2*(lengh*width+lengh*height+width*height)<<endl;    cout<<endl;}int main(){    Bulk b[5]= {Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};    b[4].get_value();    for(int i=0; i<5; i++)    {        cout<<"第"<<i+1<<"个长方柱:"<<endl;        b[i].display();    }    return 0;}


运行结果:

0 0
原创粉丝点击