# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name: 1
Author : LPP
E-mail : l.piaopiao@qq.com
date: 2018/8/1
-------------------------------------------------
Change Activity:
2018/8/1:
-------------------------------------------------
"""
"""
作业:
面向对象人力资源管理系统:
- 能存多个员工信息
(每个员工的信息有:姓名、年龄、工号、薪资、职位、部门)
- 新员工入职(添加员工)
- 员工离职(删除员工)
- 查看某个员工的信息
- 查询薪资最高的员工
- 查询指定部门中所有员工的平均薪资
- 求整个公司的员工的平均年龄
"""
class Staff:
def __init__(self, name, age, num='', salary=0, post='', department=''):
self.name = name
self.age = age
self.num = num
self.salary = salary
self.post = post
self.department = department
def print_staff_info(self): # (每个员工的信息有:姓名、年龄、工号、薪资、职位、部门)
print('姓名: ', self.name)
print('年龄: ', self.age)
print('工号: ', self.num)
print('薪资: ', self.salary)
print('职位: ', self.post)
print('部门: ', self.department)
class Company:
__staff_No = 0 # 员工工号编号基数
def __init__(self):
self.name = ''
self.staffs = []
self.staff_num = 0 # 员工数量
@classmethod
def __get_No(cls):
cls.__staff_No += 1
num = 'py1805' + str(cls.__staff_No).rjust(4, '0')
return num
def new_staff(self):
name = input('姓名:')
age = int(input('年龄:'))
num = Company.__get_No()
salary = int(input('薪资:'))
post = input('职位:')
department = input('部门:')
staff = Staff(name, age, num, salary, post, department)
self.staffs.append(staff)
self.staff_num += 1
return staff
def show_staff_info(self, flag):
"""1. 按姓名查看
2. 按工号查看
"""
if flag == 1:
name = input('请输入需要查看信息的员工姓名:')
names = []
for staff in self.staffs:
if staff.name == name:
names.append(staff)
if not names:
print('公司暂无此员工!!')
return
for staff in names:
staff.print_staff_info()
print('=====================================')
else:
num = input('请输入需要查看信息的员工工号:')
for staff in self.staffs:
count = 0
if staff.num == num:
count += 1
staff.print_staff_info()
return True
print('该工号有误,或没有对应的员工')
return False
def del_staff(self, staff_No):
for staff in self.staffs:
if staff.num == staff_No:
self.staffs.remove(staff)
self.staff_num -= 1
return True
print('没有找到该员工')
return False
def best_wages(self):
"""
:return: (薪资最高者的姓名,薪资最高者)
"""
the_highest = self.staffs[0]
for staff in self.staffs:
if staff.salary > the_highest.salary:
the_highest = staff
return the_highest.name, the_highest
def specified_part_aver_salary(self, department):
"""
:param department: 部门名称
:return: 平均薪资
"""
all_salary = []
count = 0
for staff in self.staffs:
if staff.department == department:
count += 1
all_salary.append(staff.salary)
if all_salary:
return sum(all_salary)/count
else:
print('没有这个部门或者这个部门还没有人')
def aver_age(self):
all_age = 0
for staff in self.staffs:
all_age += staff.age
if all_age:
return all_age/self.staff_num
if __name__ == '__main__':
company = Company()
company.new_staff()
company.show_staff_info()
company.best_wages()
company.del_staff()
网友评论