码迷,mamicode.com
首页 > 其他好文 > 详细

类和对象

时间:2014-09-14 15:11:57      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   2014   div   

#include <iostream>
using namespace std;
class Building
{    int Floors,Rooms;  double Total_area;
public:
    Building( int f,int r,double t)
    {   Floors=f;   Rooms=r;  Total_area=t;    }
    void disp_b()
    {   cout<<"Floors:"<<Floors<<endl;
        cout<<"Rooms:"<<Rooms<<endl;
        cout<<"Total area:"<<Total_area<<endl;
    }
};
class Housing : public Building
{   int Bedrooms,Bathrooms;
public:
    Housing( int f,int r,double t,int be,int ba): Building(f,r,t)
    {   Bedrooms=be;    Bathrooms=ba;    }
    void disp_h()
    {   cout<<"HOUSING:"<<endl;
        disp_b();
        cout<<"Bedrooms:"<<Bedrooms<<endl;
        cout<<"Bathrooms:"<<Bathrooms<<endl;
    }
};
class Office : public Building
{   int Extinguishers,Phones;
public:
    Office( int f,int r,double t,int ex,int ph)  :Building(f,r,t)
    {   Extinguishers=ex;    Phones=ph;   }
    void disp_o()
    {   cout<<"OFFICING:"<<endl;
        disp_b();
        cout<<"Extinguishers:"<<Extinguishers<<endl;
        cout<<"Phones:"<<Phones<<endl;
    }
};
int main( )
{   int t,a,b,d,e;  double c;
    cin>>t;
    while (t--)
    {   cin>>a>>b>>c>>d>>e;    Housing h1(a,b,c,d,e);
        cin>>a>>b>>c>>d>>e;   Office  o1(a,b,c,d,e);
        h1.disp_h();      o1.disp_o();
    }
    return 0;
}

bubuko.com,布布扣

类和对象

标签:style   blog   http   color   io   os   ar   2014   div   

原文地址:http://www.cnblogs.com/fantasy12436109/p/3970975.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!