给定N个职员的信息,包括基本名字、基本工资、浮动工资和支出,要求编写顺序输出每位职员的姓名和实发工资(实发工资=基本工资+浮动工资-支出)
时间: 2024-06-14 20:05:23 浏览: 147
做一个工资管理系统,要能按照姓名和卡号查找员工的工资信息,以及员工工资信息的插入,删除同时这些信息要存txt
5星 · 资源好评率100%
以下是一个示例程序,用于给定N个职员的信息,包括姓名、基本工资、浮动工资和支出,并按顺序输出每位职员的姓名和实发工资(实发工资=基本工资+浮动工资-支出):
```python
class Staff:
def __init__(self, name, basic_salary, floating_salary, expenditure):
self.name = name
self.basic_salary = basic_salary
self.floating_salary = floating_salary
self.expenditure = expenditure
def calculate_salary(staff):
return staff.basic_salary + staff.floating_salary - staff.expenditure
def print_staff_salary(staff_list):
for staff in staff_list:
salary = calculate_salary(staff)
print("姓名:{},实发工资:{}".format(staff.name, salary))
# 输入员工信息
def input_data(staff_list, n):
for i in range(n):
name = input("请输入第{}位职员的姓名:".format(i+1))
basic_salary = float(input("请输入第{}位职员的基本工资:".format(i+1)))
floating_salary = float(input("请输入第{}位职员的浮动工资:".format(i+1)))
expenditure = float(input("请输入第{}位职员的支出:".format(i+1)))
staff = Staff(name, basic_salary, floating_salary, expenditure)
staff_list.append(staff)
# 测试示例
staff_list = []
n = int(input("请输入职员的个数:"))
input_data(staff_list, n)
print_staff_salary(staff_list)
```
阅读全文