关于房间的一个类
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;
}
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号