2015年第二周项目二:长方柱类

来源:互联网 发布:linux重启网络服务失败 编辑:程序博客网 时间:2024/06/05 21:45
#include <iostream>using namespace std;class Bulk{private:    double length;    double width;    double heigth;    double volume;    double area;public:    double setxyz()    {        cin>>length;        cin>>width;        cin>>heigth;        get_areas();        get_volume();    }    void get_volume()    {        volume=length*width*heigth;    }    void get_areas()    {        area=2*(length*width+length*heigth+width*heigth);    }    void display()    {        cout<<"the volume is:"<<volume<<'\t';        cout<<"the area is:"<<area;    }};int main(){    Bulk b1,b2,b3;    b1.setxyz();    b2.setxyz();    b3.setxyz();    cout<<"b1:";    b1.display();    cout<<endl;    cout<<"b2:";    b2.display();    cout<<endl;    cout<<"b3:";    b3.display();   return 0;}

0 0
原创粉丝点击