6、为学校人事部门设计一个简单的人事管理程序,满足如下要求: (1)学校人员分为三类:教师、学生、职员; (2)三类人员的共同属性是姓名、性别、年龄、部门; (3)教师的特别属性是职称、主讲课程; (4)学生的特别属性是专业、入学日期; (4)职员的特别属性是工资; (5)统计学校总人数和各类人员的人数。
时间: 2024-02-12 09:04:00 浏览: 181
学校人员管理程序
这个人事管理程序可以使用面向对象的编程语言来实现。
首先,可以创建一个Person类作为基类,包含姓名、性别、年龄和部门属性。然后,可以创建一个Teacher类、一个Student类和一个Staff类,它们继承自Person类,并且分别添加职称、主讲课程、专业、入学日期和工资属性。
接下来,可以创建一个School类,包含一个人员列表属性,该列表包含所有教师、学生和职员的实例。在School类中,可以编写方法来添加、删除和更新人员信息,以及统计学校总人数和各类人员的人数。
以下是一个示例代码:
```python
class Person:
def __init__(self, name, gender, age, department):
self.name = name
self.gender = gender
self.age = age
self.department = department
class Teacher(Person):
def __init__(self, name, gender, age, department, title, course):
super().__init__(name, gender, age, department)
self.title = title
self.course = course
class Student(Person):
def __init__(self, name, gender, age, department, major, admission_date):
super().__init__(name, gender, age, department)
self.major = major
self.admission_date = admission_date
class Staff(Person):
def __init__(self, name, gender, age, department, salary):
super().__init__(name, gender, age, department)
self.salary = salary
class School:
def __init__(self):
self.personnel = []
def add_person(self, person):
self.personnel.append(person)
def remove_person(self, person):
if person in self.personnel:
self.personnel.remove(person)
def update_person(self, person, attribute, value):
if person in self.personnel:
setattr(person, attribute, value)
def count_personnel(self):
total = len(self.personnel)
teachers = len([person for person in self.personnel if isinstance(person, Teacher)])
students = len([person for person in self.personnel if isinstance(person, Student)])
staff = len([person for person in self.personnel if isinstance(person, Staff)])
return total, teachers, students, staff
```
可以使用该程序来创建学校和人员实例,并对人员信息进行添加、删除、更新和统计。例如:
```python
# 创建学校实例
school = School()
# 创建教师、学生和职员实例
teacher1 = Teacher('Tom', 'Male', 35, 'Math Department', 'Associate Professor', 'Linear Algebra')
teacher2 = Teacher('Mary', 'Female', 42, 'English Department', 'Professor', 'British Literature')
student1 = Student('John', 'Male', 20, 'Computer Science', 'Software Engineering', '2020-09-01')
student2 = Student('Jane', 'Female', 19, 'Biology', 'Biotechnology', '2021-03-01')
staff1 = Staff('Peter', 'Male', 28, 'Administration', 3000)
staff2 = Staff('Lisa', 'Female', 30, 'Finance', 3500)
# 添加人员信息到学校实例中
school.add_person(teacher1)
school.add_person(teacher2)
school.add_person(student1)
school.add_person(student2)
school.add_person(staff1)
school.add_person(staff2)
# 统计学校总人数和各类人员的人数
total, teachers, students, staff = school.count_personnel()
print(f'Total personnel: {total}')
print(f'Teachers: {teachers}')
print(f'Students: {students}')
print(f'Staff: {staff}')
# 更新教师信息
school.update_person(teacher1, 'title', 'Professor')
# 删除职员信息
school.remove_person(staff2)
```
输出结果为:
```
Total personnel: 6
Teachers: 2
Students: 2
Staff: 2
```
阅读全文