用Python为学校人事部门设计一个简单的人事管理程序,满足如下要求: (1)学校人员分为三类:教师、学生、职员; (2)三类人员的共同属性是姓名、性别、年龄、部门; (3)教师的特别属性是职称、主讲课程; (4)学生的特别属性是专业、入学日期: (5) 职员的特别属性是工资。
时间: 2024-05-12 15:15:45 浏览: 133
下面是一个简单的Python程序,实现了上述要求:
```python
class Person:
def __init__(self, name, sex, age, department):
self.name = name
self.sex = sex
self.age = age
self.department = department
class Teacher(Person):
def __init__(self, name, sex, age, department, title, course):
super().__init__(name, sex, age, department)
self.title = title
self.course = course
class Student(Person):
def __init__(self, name, sex, age, department, major, admission_date):
super().__init__(name, sex, age, department)
self.major = major
self.admission_date = admission_date
class Staff(Person):
def __init__(self, name, sex, age, department, salary):
super().__init__(name, sex, age, department)
self.salary = salary
# 测试代码
teacher = Teacher("张三", "男", 35, "计算机科学与技术", "副教授", "计算机网络")
print(f"教师:{teacher.name},性别:{teacher.sex},年龄:{teacher.age},部门:{teacher.department},职称:{teacher.title},主讲课程:{teacher.course}")
student = Student("李四", "女", 20, "计算机科学与技术", "软件工程", "2020-09-01")
print(f"学生:{student.name},性别:{student.sex},年龄:{student.age},部门:{student.department},专业:{student.major},入学日期:{student.admission_date}")
staff = Staff("王五", "男", 30, "行政部门", 5000)
print(f"职员:{staff.name},性别:{staff.sex},年龄:{staff.age},部门:{staff.department},工资:{staff.salary}")
```
输出结果:
```
教师:张三,性别:男,年龄:35,部门:计算机科学与技术,职称:副教授,主讲课程:计算机网络
学生:李四,性别:女,年龄:20,部门:计算机科学与技术,专业:软件工程,入学日期:2020-09-01
职员:王五,性别:男,年龄:30,部门:行政部门,工资:5000
```
阅读全文