编写一个程序实现小型公司的工资管理。该公司雇员(Employee)包括经理(Manager)、技术人员(Technician)、销售员(Salesman)和销售部经理(Salesmanager) 要求
时间: 2024-12-05 09:16:14 浏览: 13
为了编写一个小型公司的工资管理程序,我们可以创建一个Employee基类,然后为经理、技术人员、销售员和销售部经理等员工类型创建具体的子类。每个子类可以包含特有的属性如职位津贴和计算基本工资的方法。这里是一个简单的Python示例:
```python
class Employee:
def __init__(self, name, id, salary):
self.name = name
self.id = id
self.salary = salary
def get_salary(self):
return self.salary
# 子类
class Manager(Employee):
def __init__(self, name, id, basic_salary, bonus):
super().__init__(name, id, basic_salary)
self.bonus = bonus
def get_total_salary(self):
return self.get_salary() + self.bonus
class Technician(Employee):
def __init__(self, name, id, hourly_rate, hours_per_week):
super().__init__(name, id, hourly_rate * hours_per_week)
def calculate_bonus(self, performance_score):
return performance_score * self.salary / 100
class Salesman(Employee):
def __init__(self, name, id, base_sales, commission_rate):
super().__init__(name, id, base_sales * commission_rate)
def get_total_sales(self, actual_sales):
return self.base_sales + (actual_sales - self.base_sales) * self.commission_rate
class Salesmanager(Employee):
def __init__(self, name, id, base_salary, commission_on_sales):
super().__init__(name, id, base_salary)
self.commission_on_sales = commission_on_sales
def get_commission(self, total_sales):
return total_sales * self.commission_on_sales
# 使用示例
manager = Manager("张经理", 1, 5000, 1000)
technician = Technician("李工", 2, 30, 40)
salesman = Salesman("王销售", 3, 8000, 0.1)
salesmanager = Salesmanager("赵主管", 4, 7000, 0.05)
print(manager.get_total_salary()) # 经理总工资
print(technician.calculate_bonus(90)) # 技术员绩效奖金
print(salesman.get_total_sales(10000)) # 销售员实际销售额及佣金
print(salesmanager.get_commission(200000))
阅读全文