完成一个企业员工管理系统(EmployeeManagementSystem), 员工信息(工号,姓名,性别,职位,月薪)功能点: 1. 员工入职(添加) 2. 调整员工的月薪 3. 查询所有员工 4. 根据员工的工号显示员工信息 5. 删除指定工号的员工 6. 统计一个月发放的总工资
时间: 2024-04-14 12:30:33 浏览: 101
好的,我明白了。以下是一个简单的企业员工管理系统的示例代码:
```python
class Employee:
def __init__(self, emp_id, name, gender, position, salary):
self.emp_id = emp_id
self.name = name
self.gender = gender
self.position = position
self.salary = salary
class EmployeeManagementSystem:
def __init__(self):
self.employees = []
def add_employee(self, emp_id, name, gender, position, salary):
employee = Employee(emp_id, name, gender, position, salary)
self.employees.append(employee)
def adjust_salary(self, emp_id, new_salary):
for employee in self.employees:
if employee.emp_id == emp_id:
employee.salary = new_salary
break
def get_all_employees(self):
return self.employees
def get_employee_by_id(self, emp_id):
for employee in self.employees:
if employee.emp_id == emp_id:
return employee
return None
def delete_employee(self, emp_id):
for employee in self.employees:
if employee.emp_id == emp_id:
self.employees.remove(employee)
break
def calculate_total_salary(self):
total_salary = 0
for employee in self.employees:
total_salary += employee.salary
return total_salary
# 使用示例
ems = EmployeeManagementSystem()
# 添加员工
ems.add_employee(1, 'John', 'Male', 'Manager', 5000)
ems.add_employee(2, 'Alice', 'Female', 'Engineer', 4000)
ems.add_employee(3, 'Bob', 'Male', 'Assistant', 3000)
# 调整员工薪资
ems.adjust_salary(2, 4500)
# 查询所有员工
all_employees = ems.get_all_employees()
for employee in all_employees:
print(f"工号: {employee.emp_id}, 姓名: {employee.name}, 性别: {employee.gender}, 职位: {employee.position}, 月薪: {employee.salary}")
# 根据工号显示员工信息
employee = ems.get_employee_by_id(1)
if employee:
print(f"工号: {employee.emp_id}, 姓名: {employee.name}, 性别: {employee.gender}, 职位: {employee.position}, 月薪: {employee.salary}")
# 删除员工
ems.delete_employee(3)
# 统计一个月发放的总工资
total_salary = ems.calculate_total_salary()
print(f"一个月发放的总工资: {total_salary}")
```
请注意,这只是一个简单的示例,实际的员工管理系统可能需要更多的功能和数据验证。你可以根据自己的需求进行修改和扩展。
阅读全文