zoukankan      html  css  js  c++  java
  • 关于房间的一个类

    class Room
    {
    int room_no;
    double length;
    double width;
    public:
    Room(int the_room_no, double the_length, double the_width) :room_no(the_room_no),
    length(the_length), width(the_width){}
    int theRoomNo()const { return room_no; }
    double theLength()const { return length; }
    double theWidth()const{ return width; }
    double theArea()const { return length*width; }
    };
    class Office :public Room
    {
    char* depart;
    public:
    Office(int the_room_no, double the_length, double the_width, const char* the_depart) :
    Room(the_room_no, the_length, the_width)
    {
    depart = new char[strlen(the_depart) + 1];
    strcpy(depart, the_depart);
    }
    ~Office(){ delete[]depart; }
    const char* theDepartment()const
    {
    return depart;
    }
    };

    int main()
    {
    Office an_office(308, 5.6, 4.8, "会计科");
    cout << "办公室房间号:" << an_office.theRoomNo() << endl;
    cout << "办公室长度:" << an_office.theLength() << endl;
    cout << "办公室宽度:" << an_office.theWidth() << endl;
    cout << "办公室面积:" << an_office.theArea() << endl;
    cout << "办公室所属部门:" << an_office.theDepartment() << endl;
    return 0;
    }

  • 相关阅读:
    hdu4578线段树维护平方和,立方和(加,乘,赋值)或者珂朵莉树
    珂朵莉树(ODT老司机树)
    Codeforces Round #524 (Div. 2)D
    HDU1402 FFT高精度乘法模板题
    中国剩余定理poj1006
    POJ
    Install and Config MySQL 8 on Ubuntu
    Protobuf Examples
    Learning Thrift
    Flask Quickstart
  • 原文地址:https://www.cnblogs.com/huninglei/p/5458102.html
Copyright © 2011-2022 走看看