zoukankan      html  css  js  c++  java
  • 类和对象

    #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;
    }

  • 相关阅读:
    Java面向对象——属性赋值的过程
    Java面向对象——类的成员之三:构造器(构造方法)constructor
    课后作业—5
    缓冲类的使用示例
    缓冲技术
    流的基类
    流的分类
    什么是流?
    关于开发中异常处理的建议
    阅读笔记-3
  • 原文地址:https://www.cnblogs.com/fantasy12436109/p/3970975.html
Copyright © 2011-2022 走看看