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

  • 相关阅读:
    解决svn Authorization failed错误
    jQuery切换事件
    jQuery学习笔记
    EAS开发
    JavaScript第二课
    JavaScript学习第一课
    EAS常用工具类
    [转]OpenBLAS项目与矩阵乘法优化
    [转]mmap和madvise的使用
    [转]C++赋值运算符重载函数(operator=)
  • 原文地址:https://www.cnblogs.com/huninglei/p/5458102.html
Copyright © 2011-2022 走看看