第2周项目2长方柱类计算3个长方柱的体积及表面积

来源:互联网 发布:奢侈品辨别真假软件 编辑:程序博客网 时间:2024/04/27 14:51
/*日期:2014年3月14日;*作者:范星月*问题描述:计算长方柱的表面积及体积*问题输入:输入长宽高*问题输出:输出结果*/#include <iostream>using namespace std;class Bulk{    public:    void  get_value();    void  display();private:    float length;    float width;    float heigth;    float volume;    float  areas;    void get_volume();    void get_areas();};void Bulk::get_value(){    cin>>length>>width>>heigth;    get_volume();    get_areas();}void  Bulk::get_volume(){    volume= length*width*heigth;}void Bulk::get_areas(){    areas= 2*length*width+2*length*heigth+2*width*heigth;}void Bulk::display(){    cout<<"volume:"<<volume<<endl;    cout<<"areas:"<<areas;}int main(){    Bulk b1,b2,b3;    b1.get_value();    cout<<"for b1:"<<endl;    b1.display();    b2.get_value();    cout<<"for b2:"<<endl;    b2.display();    b3.get_value();    cout<<"for b3:"<<endl;    b3.display();    return 0;}


 

学习总结:

定义Bulk类,四个成员函数(两个共有,两个私有),五个数据成员,数据成员可以在成员函数中调用,但不可以在main函数中调用,直接在main函数中调用public成员函数,可以实现输入与输出,public成员函数是联系内外的接口

 

0 0
原创粉丝点击