实训室管理系统的实现代码
时间: 2023-10-26 22:15:46 浏览: 126
实训室管理系统的实现代码可能会比较复杂,并且需要考虑具体需求和功能。以下是一个简单的实训室管理系统的实现代码:
```python
class TrainingRoom:
def __init__(self, id, name, capacity):
self.id = id
self.name = name
self.capacity = capacity
self.available = True
def __str__(self):
return f"{self.id}\t{self.name}\t{self.capacity}\t{self.available}"
class TrainingRoomManager:
def __init__(self):
self.rooms = []
def add_room(self, room):
self.rooms.append(room)
def remove_room(self, room_id):
for room in self.rooms:
if room.id == room_id:
self.rooms.remove(room)
def get_available_rooms(self):
available_rooms = []
for room in self.rooms:
if room.available:
available_rooms.append(room)
return available_rooms
def reserve_room(self, room_id):
for room in self.rooms:
if room.id == room_id:
if room.available:
room.available = False
return True
else:
return False
def release_room(self, room_id):
for room in self.rooms:
if room.id == room_id:
room.available = True
return True
return False
def main():
room_manager = TrainingRoomManager()
room1 = TrainingRoom(1, "Training Room 1", 20)
room2 = TrainingRoom(2, "Training Room 2", 30)
room3 = TrainingRoom(3, "Training Room 3", 40)
room_manager.add_room(room1)
room_manager.add_room(room2)
room_manager.add_room(room3)
print("Available Rooms:")
available_rooms = room_manager.get_available_rooms()
for room in available_rooms:
print(room)
print("Reserving Room 1")
if room_manager.reserve_room(1):
print("Room 1 Reserved")
else:
print("Room 1 Not Available")
print("Available Rooms:")
available_rooms = room_manager.get_available_rooms()
for room in available_rooms:
print(room)
print("Releasing Room 1")
if room_manager.release_room(1):
print("Room 1 Released")
else:
print("Room 1 Not Found")
print("Available Rooms:")
available_rooms = room_manager.get_available_rooms()
for room in available_rooms:
print(room)
if __name__ == '__main__':
main()
```
以上代码实现了一个实训室管理系统,包括实训室类和实训室管理器类。其中,实训室类包含了实训室的基本属性和方法,包括编号、名称、容量和是否可用等;实训室管理器类包含了实训室的管理方法,包括添加实训室、删除实训室、获取可用实训室、预约实训室和释放实训室等。在主函数中,我们创建了三个实训室,添加到实训室管理器中,并进行了一些简单的预约和释放操作,以展示实训室管理系统的基本功能。
阅读全文