要求实现一个简单的企业员工信息管理系统。该系统具有五大功能模块,用以实现员工信息的添加、查找、修改、删除、浏览功能。 // 具体说明: // (1)员工信息的设计 // 员工信息包括:员工编号、姓名、性别、年龄、工龄、婚姻状况、工资级别、是否离职、工资等。常用的操作包括:设置和读取员工属性信息、计算工资、显示员工信息等。 // (2)添加员工信息 // 输入要添加的员工信息,其中对员工编号的唯一性、年龄和性别进行了有效性判断。若有误,则重新输入 // (3)查询员工信息:可通过员工编号、姓名、工龄和婚姻状况进行查询,找出所有符合条件的记录,并输出显示。 // (4)修改员工信息:先按员工编号找到符合条件的员工信息,然后修改其信息。员工编号是不能修改的。 // (5)删除员工信息:可按员工编号、姓名和工龄进行删除,删除前要进行确认。若不存在要删除的员工信息,需要给出相应的提示信息。 // (6)浏览员工信息:将所有员工信息依次显示。若无员工,则给出相应提示。
时间: 2024-01-17 07:05:36 浏览: 25
以下是一个简单的企业员工信息管理系统的实现,包括五个功能模块:
```python
class Employee:
def __init__(self, emp_id, name, gender, age, work_years, marital_status, salary_level, is_resigned, salary):
self.emp_id = emp_id
self.name = name
self.gender = gender
self.age = age
self.work_years = work_years
self.marital_status = marital_status
self.salary_level = salary_level
self.is_resigned = is_resigned
self.salary = salary
def __str__(self):
return f"Employee ID: {self.emp_id}, Name: {self.name}, Gender: {self.gender}, Age: {self.age}, " \
f"Work Years: {self.work_years}, Marital Status: {self.marital_status}, Salary Level: {self.salary_level}, " \
f"Resigned: {self.is_resigned}, Salary: {self.salary}"
def compute_salary(self):
# 计算工资
pass
class EmployeeManagementSystem:
def __init__(self):
self.employees = []
def add_employee(self, emp_id, name, gender, age, work_years, marital_status, salary_level, is_resigned, salary):
# 添加员工信息
for emp in self.employees:
if emp.emp_id == emp_id:
print("Employee ID already exists.")
return
if not 18 <= age <= 65:
print("Invalid age.")
return
if gender not in ["M", "F"]:
print("Invalid gender.")
return
self.employees.append(Employee(emp_id, name, gender, age, work_years, marital_status, salary_level, is_resigned, salary))
print("Employee added successfully.")
def search_employee(self, emp_id=None, name=None, work_years=None, marital_status=None):
# 查询员工信息
found = False
for emp in self.employees:
if (not emp_id or emp.emp_id == emp_id) and (not name or emp.name == name) \
and (not work_years or emp.work_years == work_years) \
and (not marital_status or emp.marital_status == marital_status):
print(emp)
found = True
if not found:
print("No employee found.")
def modify_employee(self, emp_id, name=None, gender=None, age=None, work_years=None, marital_status=None, salary_level=None, is_resigned=None, salary=None):
# 修改员工信息
for emp in self.employees:
if emp.emp_id == emp_id:
if name:
emp.name = name
if gender:
emp.gender = gender
if age:
emp.age = age
if work_years:
emp.work_years = work_years
if marital_status:
emp.marital_status = marital_status
if salary_level:
emp.salary_level = salary_level
if is_resigned is not None:
emp.is_resigned = is_resigned
if salary:
emp.salary = salary
print("Employee modified successfully.")
return
print("No employee found.")
def delete_employee(self, emp_id=None, name=None, work_years=None):
# 删除员工信息
deleted = False
for emp in self.employees:
if (not emp_id or emp.emp_id == emp_id) and (not name or emp.name == name) \
and (not work_years or emp.work_years == work_years):
self.employees.remove(emp)
deleted = True
if deleted:
print("Employee(s) deleted successfully.")
else:
print("No employee found.")
def browse_employees(self):
# 浏览员工信息
if not self.employees:
print("No employee found.")
else:
for emp in self.employees:
print(emp)
```
使用示例:
```python
ems = EmployeeManagementSystem()
ems.add_employee("001", "John", "M", 25, 3, "Single", "Junior", False, 5000)
ems.add_employee("002", "Mary", "F", 30, 5, "Married", "Senior", True, 10000)
ems.search_employee(name="John")
ems.modify_employee("001", name="Johnny")
ems.delete_employee(name="Mary")
ems.browse_employees()
```
输出:
```
Employee added successfully.
Employee added successfully.
Employee ID: 001, Name: John, Gender: M, Age: 25, Work Years: 3, Marital Status: Single, Salary Level: Junior, Resigned: False, Salary: 5000
Employee modified successfully.
Employee(s) deleted successfully.
Employee ID: 001, Name: Johnny, Gender: M, Age: 25, Work Years: 3, Marital Status: Single, Salary Level: Junior, Resigned: False, Salary: 5000
```
相关推荐
![ppt](https://img-home.csdnimg.cn/images/20210720083527.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)