关于房间的一个类

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

posted @ 2016-05-04 13:32  huninglei  阅读(170)  评论(0编辑  收藏  举报