python-
设计高校人员信息包,并完成测试
【题目描述】定义一个人员类People,其属性有:姓名、性别、年龄;基于People实现学生类Student,添加属性:学号、入学时间和入学成绩;基于People实现教师类Teacher,添加属性:职务、部门、工作时间;基于Student实现究生类Graduate,添加属性:研究方向和导师,分别定义其中的构造函数和输出函数。程序中定义各种类的对象,并完成测试。 基于以上类利用接口实现在职研究生类 GradOnWork。
【源代码程序】
class People:
def __init__(self, name='lll', gender='女', age=18):
self.name = name
self.gender = gender
self.age = age
def display(self):
print("姓名:" + self.name + "\n性别:" + self.gender + "\n年龄:" + str(self.age))
class Student(People):
def __init__(self, student_id="20210001", into_time="2021-09-01", into_score="100.0"):
People.__init__(self, name='lll', gender='女', age=18)
self.student_id = student_id
self.into_time = into_time
self.into_score = into_score
def display(self):
print("姓名:" + self.name + "\n性别:" + self.gender + "\n年龄:" + str(self.age) + "\n学号:" + self.student_id + "\n入学时间:" + self.into_time + "\n入学成绩:" + str(self.into_score))
class Teacher(People):
def __init__(self, post="院长", department="软件工程学院", job_time="2000-1-01"):
People.__init__(self, name='wsx', gender='男', age=40)
self.post = post
self.department = department
self.job_time = job_time
def display(self):
print("姓名:" + self.name + "\n性别:" + self.gender + "\n年龄:" + str(self.age) + "\n职务:" + self.post + "\n部门:" + self.department + "\n工作时间:" + self.job_time)
class Graduate(Student):
def __init__(self, research_fields="额", teacher="wjm"):
Student.__init__(self, student_id="2022888", into_time="2022-09-01", into_score="60.0")
self.research_fields = research_fields
self.teacher = teacher
def display(self):
print("姓名:" + self.name + "\n性别:" + self.gender + "\n年龄:" + str(self.age) + "\n学号:" + self.student_id + "\n入学时间:" + self.into_time + "\n入学成绩:" + str(self.into_score) + "\n研究方向:" + self.research_fields + "\n导师:" + self.teacher)
class GradOnWork(Teacher, Graduate):
def __init__(self):
Teacher.__init__(self, post="辅导员", department="软件工程学院", job_time="2000-1-01")
Graduate.__init__(self, research_fields="人工智能", teacher="wjm")
def display(self):
print("姓名:" + self.name + "\n性别:" + self.gender + "\n年龄:" + str(self.age) + "\n职务:" + self.post + "\n部门:" + self.department + "\n工作时间:" + self.job_time + "\n学号:" + self.student_id + "\n入学时间:" + self.into_time + "\n入学成绩:" + str(self.into_score) + "\n研究方向:" + self.research_fields + "\n导师:" + self.teacher)
# 创建一个 GradOnWork 对象
grad_on_work = GradOnWork()
# 调用 display() 方法打印信息
grad_on_work.display()