2. 编程实现模拟简单的企业职工管理程序。请按继承层次构建企业的各种职工类型,包括超类Employee,以及相应的子类Manager、Secretary和Programmer,从Manager继承又可得到Executive。超类Employee有编号,姓名,年龄,工资、地址和雇佣日期等信息。普通职工Employee的薪资只有基本工资, Manager、Secretary和Programmer的薪资为基本工资再加上10%奖金,而Executive的薪资为基本工资再加15的奖金,使用数组来存储员工对象,实现员工的遍历和查找功能(即输出所有员工对象的信息和,查找某个员工对象的信息)
时间: 2024-02-01 08:13:54 浏览: 72
zl_3.rar_职工管理系统
以下是一个简单的企业职工管理程序的实现:
```python
class Employee:
def __init__(self, ID, name, age, salary, address, hire_date):
self.ID = ID
self.name = name
self.age = age
self.salary = salary
self.address = address
self.hire_date = hire_date
def __str__(self):
return f"ID: {self.ID}, Name: {self.name}, Age: {self.age}, Salary: {self.salary}, Address: {self.address}, Hire Date: {self.hire_date}"
class Manager(Employee):
def __init__(self, ID, name, age, salary, address, hire_date):
super().__init__(ID, name, age, salary, address, hire_date)
def get_salary(self):
return self.salary * 1.1
class Secretary(Employee):
def __init__(self, ID, name, age, salary, address, hire_date):
super().__init__(ID, name, age, salary, address, hire_date)
def get_salary(self):
return self.salary * 1.1
class Programmer(Employee):
def __init__(self, ID, name, age, salary, address, hire_date):
super().__init__(ID, name, age, salary, address, hire_date)
def get_salary(self):
return self.salary * 1.1
class Executive(Manager):
def __init__(self, ID, name, age, salary, address, hire_date):
super().__init__(ID, name, age, salary, address, hire_date)
def get_salary(self):
return self.salary * 1.15
# 创建员工对象
employees = []
employees.append(Manager(1, "John", 35, 5000, "New York", "2010-01-01"))
employees.append(Secretary(2, "Jane", 25, 3000, "Los Angeles", "2012-06-01"))
employees.append(Programmer(3, "Mike", 30, 4000, "Chicago", "2015-05-01"))
employees.append(Executive(4, "Tom", 40, 6000, "San Francisco", "2008-03-01"))
# 遍历员工对象
for employee in employees:
print(employee)
# 查找员工对象
for employee in employees:
if employee.ID == 2:
print(employee)
```
在上面的代码中,我们先定义了一个超类Employee,包括编号、姓名、年龄、工资、地址和雇佣日期等信息。然后,我们定义了Manager、Secretary、Programmer和Executive这四个子类,分别继承自Employee,并且分别实现了get_salary方法来计算薪资。最后,我们创建了一个员工对象数组,存储了不同类型的员工对象。我们可以遍历这些员工对象并输出它们的信息,也可以通过遍历查找某个员工对象的信息。
阅读全文