马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
typedef struct Employee{
int id;
char password[50];
char name[50];
float salary;
float tax;
struct Employee*next;
}Employee;
// 全局变量,用于存储员工链表的头指针
Employee*head=NULL;
// 管理员登录函数
int adminLogin()
{
char password[20];
printf("请输入管理员密码:");
scanf("%s",password);
if(strcmp(password,"2597658468")==0)
{
return 1;
}
else
{
return 0;
}
}
// 录入员工信息并计算税金
void addEmployee()
{
int i,m;
Employee*newEmployee =(Employee*)malloc(sizeof(Employee));
printf("职工人数(1--100):");
scanf("%d",&m);
for(i=0;i<m;i++)
{
printf("请输入员工工号:");
scanf("%d",&newEmployee->id);
printf("请输入员工密码:");
scanf("%s",newEmployee->password);
printf("请输入员工姓名:");
scanf("%s",&newEmployee->name);
printf("请输入员工工资:");
scanf("%f",&newEmployee->salary);
if(newEmployee->salary<=3000)
{
newEmployee->tax=newEmployee->salary*0.03;
}
else if(newEmployee->salary>3000&&newEmployee->salary<=12000)
{
newEmployee->tax=(newEmployee->salary-3000)*0.10;
}
else if(newEmployee->salary>12000&&newEmployee->salary<=25000)
{
newEmployee->tax=(newEmployee->salary-12000)*0.20;
}
else if(newEmployee->salary>25000&&newEmployee->salary<=35000)
{
newEmployee->tax=(newEmployee->salary-25000)*0.25;
}
else if(newEmployee->salary>35000&&newEmployee->salary<=55000)
{
newEmployee->tax=(newEmployee->salary-35000)*0.30;
}
else if(newEmployee->salary>55000&&newEmployee->salary<=80000)
{
newEmployee->tax=(newEmployee->salary-55000)*0.35;
}
else
{
newEmployee->tax=(newEmployee->salary-80000)*0.45;
}
}
newEmployee->next=head;
head=newEmployee;
}
void save(Employee*head)
{
if(head==NULL)
{
printf("节点为空,保存失败\n%s\t%d\t%s\n",__FILE__,__LINE__,__func__);
}
FILE* fp=fopen("cherk_list","wb");
if(fp==NULL)
{
printf("打开文件失败\n");
return;
}
Employee*p=head->next;
while (p!=NULL)
{
fwrite();
}
flcose(fp);
fp=NULL;
}
// 根据姓名查询员工信息
void serchEmployees()
{
int flag=1;
char name[20];
Employee* p=head;
printf("请输入你要查找的姓名: \n");
scanf("%s",name);
while(p!=NULL&&flag)
{
if(strcmp(name,p->name)==0)
{
flag=0;
}
else
{
p=p->next;
}
}
if(flag==0)
{
printf("工号\t姓名\t工资");
printf("%d\t",p->id);
printf("%s\t",p->name);
printf("%d\t",p->salary);
}
else
{
printf("没有查询到记录");
}
}
//根据姓名进行修改
void update()
{
int flag=1;
char name[20];
Employee*q=head;
printf("请输入你要查找的姓名:\n");
scanf("%s",name);
while(q!=NULL&&flag)
{
if(strcmp(name,q->name)==0)
{
printf("请输入工号: \n");scanf("%d",q->id);
printf("请输入密码:\n");scanf("%s",q->password);
printf("请输入姓名:\n");scanf("%s",q->name);
printf("请输入收入:\n");scanf("%f",q->salary);
}
}
}
// 显示所有员工的信息
void displayEmployees()
{
Employee* current =head;
while(current !=NULL)
{
printf("工号:%d\t姓名: %s\t工资: %.2f\t税金: %.2f\t",current->id,current->name,current->salary,current->tax);
current=current->next;
}
}
// 统计数目
void displayStatistics()
{
int count=0;
float totalSalary =0;
float totalTax =0;
Employee* current =head;
while(current!=NULL)
{
count++;
totalSalary+=current->salary;
totalTax+=current->tax;
current=current->next;
}
printf("员工数目:%d,工资总数: %.2f,税金总数:%.2f\n",count,totalSalary,totalTax);
}
// 主函数
int main()
{
int choice;
while(1)
{
printf("\n1.管理员登录\n2.录入员工信息\n3.查找员工信息\n4.修改员工信息\n5.显示所有员工信息\n6.显示统计信息\n7.退出\n");
printf("请输入你的选择:");
scanf("%d",&choice);
switch(choice)
{
case 1:
if(adminLogin())
{
printf("管理员登录成功!");
}
else
{
printf("管理员密码错误!");
}
break;
case 2:addEmployee();break;
case 3:serchEmployees();break;
case 4:update();break;
case 5:displayEmployees();break;
case 6:displayStatistics();break;
case 7:exit(0);
default:printf("无效的选择!\n");
}
}
return 0;
}
还有感觉有一些bug,可以帮忙修改一下吗 |