编写一个职工工资管理系统的程序代码
时间: 2023-12-11 20:03:17 浏览: 84
好的,以下是一个简单的职工工资管理系统的程序代码,使用Python语言编写:
```python
# 定义职工类
class Employee:
def __init__(self, name, id, salary):
self.name = name
self.id = id
self.salary = salary
def display_employee(self):
print(f"Name: {self.name}, ID: {self.id}, Salary: {self.salary}")
# 定义职工管理类
class EmployeeManager:
def __init__(self):
self.employees = []
# 添加职工
def add_employee(self, employee):
self.employees.append(employee)
# 显示所有职工信息
def display_all_employees(self):
for employee in self.employees:
employee.display_employee()
# 根据ID查找职工信息
def find_employee_by_id(self, id):
for employee in self.employees:
if employee.id == id:
employee.display_employee()
return
print("Employee not found.")
# 根据ID删除职工
def delete_employee_by_id(self, id):
for employee in self.employees:
if employee.id == id:
self.employees.remove(employee)
return
print("Employee not found.")
# 修改职工工资
def modify_employee_salary(self, id, new_salary):
for employee in self.employees:
if employee.id == id:
employee.salary = new_salary
return
print("Employee not found.")
# 测试代码
if __name__ == "__main__":
manager = EmployeeManager()
employee1 = Employee("John", 1001, 5000)
employee2 = Employee("Alice", 1002, 6000)
employee3 = Employee("Bob", 1003, 7000)
manager.add_employee(employee1)
manager.add_employee(employee2)
manager.add_employee(employee3)
manager.display_all_employees()
manager.find_employee_by_id(1002)
manager.modify_employee_salary(1001, 5500)
manager.display_all_employees()
manager.delete_employee_by_id(1003)
manager.display_all_employees()
```
以上代码实现了一个简单的职工工资管理系统,可以添加、查找、修改和删除职工信息。
阅读全文