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

  • 相关阅读:
    Linux磁盘与文件系统操作命令
    Linux 进程管理命令
    文件备份与压缩命令
    Linux系统命令
    CentOS6和CentOS7的区别
    nginx安装配置
    docker的容器和镜像的清理
    Zabbix-Agent配置文件详解
    k8s 获取登录token命令
    vmware 端口转发设置
  • 原文地址:https://www.cnblogs.com/huninglei/p/5458102.html
Copyright © 2011-2022 走看看