该小型企业的员工主要有 4 类:经理、技术员、销售员和计时工。要求存 储员工的工号、姓名、岗位、月工资等基本信息
时间: 2023-10-15 13:06:01 浏览: 86
可以使用面向对象编程的思想,定义一个员工类,包含工号、姓名、岗位和月工资等属性,然后派生出经理类、技术员类、销售员类和计时工类。具体实现代码如下:
```python
class Employee:
def __init__(self, id, name, position, salary):
self.id = id
self.name = name
self.position = position
self.salary = salary
class Manager(Employee):
def __init__(self, id, name, position, salary, department):
super().__init__(id, name, position, salary)
self.department = department
class Technician(Employee):
def __init__(self, id, name, position, salary, skill_level):
super().__init__(id, name, position, salary)
self.skill_level = skill_level
class Salesman(Employee):
def __init__(self, id, name, position, salary, sales_volume):
super().__init__(id, name, position, salary)
self.sales_volume = sales_volume
class HourlyWorker(Employee):
def __init__(self, id, name, position, salary, hours_worked):
super().__init__(id, name, position, salary)
self.hours_worked = hours_worked
```
以上代码定义了一个员工类和四个派生类,分别表示经理、技术员、销售员和计时工,每个类都继承了员工类的属性,并添加了额外的属性。可以根据具体需求,对这些类进行扩展和修改。
阅读全文