某学校教师行月工资的计算公式如下:固定工资+课时补贴。 教授(Protessor)的周定工资为5000元,手个课时补贴50元; 副教授(ViceProtessor)的周定工资为3000元,行个课时补贴30元; 讲师(Tutor)的周定工资为2000元,每个课时补贴20元。 定义教师(Teacher)抽象类,派生不问职称的教师子类,编写程序求若干教师的月工资
时间: 2023-12-06 19:44:21 浏览: 100
案例T-流程A标准-物料管理(MC)
根据题目给出的计算公式,可以得出以下代码实现:
```python
from abc import ABC, abstractmethod
class Teacher(ABC):
@abstractmethod
def get_salary(self):
pass
class Professor(Teacher):
def __init__(self, fixed_salary, hour_salary):
self.fixed_salary = fixed_salary
self.hour_salary = hour_salary
def get_salary(self, hour_num):
return self.fixed_salary + self.hour_salary * hour_num
class ViceProfessor(Teacher):
def __init__(self, fixed_salary, hour_salary):
self.fixed_salary = fixed_salary
self.hour_salary = hour_salary
def get_salary(self, hour_num):
return self.fixed_salary + self.hour_salary * hour_num
class Tutor(Teacher):
def __init__(self, fixed_salary, hour_salary):
self.fixed_salary = fixed_salary
self.hour_salary = hour_salary
def get_salary(self, hour_num):
return self.fixed_salary + self.hour_salary * hour_num
# 测试
professor = Professor(5000, 50)
print(professor.get_salary(10)) # 5500
vice_professor = ViceProfessor(3000, 30)
print(vice_professor.get_salary(8)) # 5400
tutor = Tutor(2000, 20)
print(tutor.get_salary(15)) # 2900
```
在这个例子中,我们定义了一个抽象类 `Teacher`,并且派生出了三个具体类 `Professor`、`ViceProfessor` 和 `Tutor`。每个类都有一个 `get_salary` 方法,用于计算教师的月工资。
最后,我们创建了三个教师对象,并且调用了他们的 `get_salary` 方法进行测试。
阅读全文