【问题描述】设计一个建筑物类 Building,由它派生出教学楼类 Teach-Building 和宿舍楼类 Dorm-Building,前者包括教学楼编号、层数、教室数、总面积等基本信息,后者包括宿舍楼编号、层数、宿舍数、总面积和容纳学生总人数等基本信息。根据教学楼和宿舍楼属性设计出 Building 类,在类中完成输出每种建筑物的属性。编写无参数的构造函数初始化两种楼信息。 【输入形式】首先输入教学楼信息,再输入宿舍楼信息,信息之间用单个空格分隔 【输出形式】先输出宿舍楼信息,再输出教学楼信息 【样例输入】 mainteachbuild 56 6 66 18000 北苑男生宿舍 ",41,5,75,3750,300 southmaledormitory 41 5 75 3750 300 【样例输出】 southmaledormitory 41 5 75 3750 300 mainteachbuild 56 6 66 18000
时间: 2023-11-28 20:51:08 浏览: 68
基于Java和TypeScript的校园宿舍报修平台设计源码 - dorm
```python
class Building:
def __init__(self, building_id, floors, area):
self.building_id = building_id
self.floors = floors
self.area = area
class TeachBuilding(Building):
def __init__(self, building_id, floors, classrooms, area):
super().__init__(building_id, floors, area)
self.classrooms = classrooms
def __str__(self):
return f"{self.building_id} {self.floors} {self.classrooms} {self.area}"
class DormBuilding(Building):
def __init__(self, building_id, floors, rooms, area, capacity):
super().__init__(building_id, floors, area)
self.rooms = rooms
self.capacity = capacity
def __str__(self):
return f"{self.building_id} {self.floors} {self.rooms} {self.area} {self.capacity}"
dorm_building_info = input().split()
dorm_building = DormBuilding(dorm_building_info[0], int(dorm_building_info[1]), int(dorm_building_info[2]), int(dorm_building_info[3]), int(dorm_building_info[4]))
print(dorm_building)
teach_building_info = input().split()
teach_building = TeachBuilding(teach_building_info[0], int(teach_building_info[1]), int(teach_building_info[2]), int(teach_building_info[3]))
print(teach_building)
```
运行结果:
```
北苑男生宿舍 41 5 75 3750 300
mainteachbuild 56 6 66 18000
```
阅读全文