在接受字符时,依旧使用的是scanf,但又因为scanf可以接收 回车 和 空格 ,所以用getchar来接收上述字符
//-------------------------------------------员工工资管理系统---------------------------------------------
#include<stdio.h>
#include<string.h>
//定义结构体数据类型
int loop=1;//控制是否退出菜单
char key;
int customernum=10;//统计客户的数量
struct Customer {int id;int year;char gh[20];int month;char name[20];char bm[20];int gz;int jx;int bt;int bx;int qt;
};
//客户结构体数组
struct Customer customers[50]={{01,2021,"DF001",10,"包宏伟","管理",40600,500,0,0,230},
{02,2021,"DF002",10,"陈万地","管理",3500,1200,0,0,352},
{03,2021,"DF003",10,"张惠","行政",12450,500,0,0,0},
{04,2021,"DF004",10,"闫朝霞","人事",6050,0,0,0,130},
{05,2021,"DF005",10,"吉祥","研发",6150,0,0,0,0},
{01,2021,"DF001",11,"包宏伟","管理",40600,500,2600,120,0},
{02,2021,"DF002",11,"陈万地","管理",3500,1200,2000,160,0},
{03,2021,"DF003",11,"张惠","行政",12450,500,2600,200,0},
{04,2021,"DF004",11,"闫朝霞","人事",6050,0,2000,200,130},
{05,2021,"DF005",11,"吉祥","研发",6150,0,2600,200,0}};//显示一个customer变量的信息p->
void Customer(struct Customer *customer){printf("\n%d\t%d\t%s\t\t%s\t\t%s\t\t%d\t\t%d\t\t%d\t\t%d\t\t%.2f\t\t%d\t\t%d\t\t%.2f",(*customer).year,(*customer).month,(*customer).gh,(*customer).name,(*customer).bm,(*customer).gz,(*customer).jx,(*customer).bt,(*customer).gz+(*customer).jx+(*customer).bt,(*customer).gz*0.05,(*customer).bx,(*customer).qt,(*customer).gz+(*customer).jx+(*customer).bt-(*customer).gz*0.05-(*customer).bx-(*customer).qt);
}//显示客户信息
void list(){int i;printf("\n 员工工资信息列表 ");printf("\n年份\t月份\t员工工号\t姓名\t\t部门\t\t岗位工资\t绩效工资\t取暖补贴\t应发合计\t公积金\t\t保险\t\t其他扣除\t实发工资");for(i=0;i<customernum;i++){Customer(&customers[i]);}getchar();
}//添加客户信息
void add(){printf("\n\t\t\t添加员工工资信息");printf("\n年份:");scanf("%d",&(customers[customernum].year));getchar();printf("\n月份:");scanf("%d",&(customers[customernum].month));getchar();printf("\n员工工号:");scanf("%s",customers[customernum].gh);getchar();printf("\n姓名:");scanf("%s",customers[customernum].name);getchar();printf("\n部门:");scanf("%s",customers[customernum].bm);getchar();printf("\n岗位工资:");scanf("%d",&(customers[customernum].gz));getchar();printf("\n绩效工资:");scanf("%d",&(customers[customernum].jx));getchar();printf("\n取暖补贴:");scanf("%d",&(customers[customernum].bt));getchar();printf("\n保险:");scanf("%d",&(customers[customernum].bx));getchar();printf("\n其他扣除:");scanf("%d",&(customers[customernum].qt));getchar();printf("\n添加已经完成");customernum++;}//删除信息
void Find(){ char i[20];int n,j;int a;int target = 1;a=customernum;printf("请输入你要删除的工号:");scanf("%s",i);getchar();for(n=0;n<customernum;n++){if(0 == strcmp(customers[n].gh,i)){target =0;for(j=n;j<customernum;j++) customers[j]=customers[j+1];}}if(target == 1){printf("没有此人信息");}else{customernum=customernum-2;}
}//修改客户信息
void revise(){char i[20];int n;int l=1;int a;char b;printf("请输入你要修改信息的工号:");scanf("%s",i);getchar();for(n=0;n<50;n++)if(0 == strcmp(customers[n].gh,i)){ a=n;printf("\n以下是将要被修改的信息:\n");printf("1.年份:%d\n",customers[n].year);printf("2.月份:%d\n",customers[n].month);printf("3.员工工号:%s\n",customers[n].gh);printf("4.姓名:%s\n",customers[n].name);printf("5.部门:%s\n",customers[n].bm);printf("6.岗位工资:%d\n",customers[n].gz);printf("7.绩效工资:%d\n",customers[n].jx);printf("8.取暖补贴:%d\n",customers[n].bt);printf("9.保险:%d\n",customers[n].bx);printf("0.其他扣除:%d\n",customers[n].qt);/*getchar();*/do{printf("请你输入修改数字:");scanf("%c",&b);switch(b){case'1':printf("\n年份:");scanf("%d",&(customers[a].year));getchar();break;case'2':printf("\n月份:");scanf("%d",&(customers[a].month));getchar();break;case'3':printf("\n员工工号:");scanf("%s",customers[a].gh);getchar();break;case'4':printf("\n姓名:");scanf("%s",customers[a].name);getchar();break;case'5':printf("\n部门:");scanf("%s",customers[a].bm);getchar();break;case'6':printf("\n岗位工资:");scanf("%d",&(customers[a].gz));getchar();break;case'7':printf("\n绩效工资:");scanf("%d",&(customers[a].jx));getchar();break;case'8':printf("\n取暖补贴:");scanf("%d",&(customers[a].bt));getchar();break;case'9':printf("\n保险:");scanf("%d",&(customers[a].bx));getchar();break;case'0':printf("\n其他扣除:");scanf("%d",&(customers[a].qt));getchar();break;}l=0;}while(l);}getchar();
}
//查找员工信息
void seek(){char ly_i[20];//姓名char ly_j[20];//工号int ly_n;int ly_b;int ly_a=0;int ly_c=1;printf("\n---------------请你选择查找方式---------------\n");printf(" 1.员工工号\n");printf(" 2.姓 名\n");scanf("%d",&ly_a);printf("请你输入:");if(ly_a==1){while(ly_c){printf("请输入你要查找的工号:");scanf("%s",ly_j);getchar();printf("\n年份\t月份\t员工工号\t姓名\t\t部门\t\t岗位工资\t绩效工资\t取暖补贴\t应发合计\t公积金\t\t保险\t\t其他扣除\t实发工资");for(ly_b=0;ly_b<customernum;ly_b++)if(0 == strcmp(customers[ly_b].gh,ly_j))//比较{Customer(&customers[ly_b]);//调用函数ly_c=0;}if(ly_c==1)printf("你输入的信息有误,请重新输入:\n");}}else//姓名{while(ly_c){printf("请输入你要查找的名字:");scanf("%s",ly_i);getchar();for(ly_n=0;ly_n<customernum;ly_n++)if(0 == strcmp(customers[ly_n].name,ly_i)){Customer(&customers[ly_n]);ly_c=0;}if(ly_c==1)printf("你输入的信息有误,请重新输入:\n");}}
}//对信息进行排序
void paixu()
{int n;int i;int j;int index;struct Customer ms;printf("\t\t\t请选择排序方式\n");printf("\t\t\t1.岗位工资\n");printf("\t\t\t2.绩效工资\n");printf("请你输入:");scanf("%d",&n);if(n==1){printf("\n年份\t月份\t员工工号\t姓名\t\t部门\t\t岗位工资\t绩效工资\t取暖补贴\t应发合计\t公积金\t\t保险\t\t其他扣除\t实发工资");for(i=0;i<customernum-1;i++){for(j=0;j<customernum-i-1;j++)if(customers[j].gz<=customers[j+1].gz){ms=customers[j];customers[j]=customers[j+1];customers[j+1]=ms;}}for(i=0;i<customernum;i++)Customer(&customers[i]);}else{if(n==2){printf("\n年份\t月份\t员工工号\t姓名\t\t部门\t\t岗位工资\t绩效工资\t取暖补贴\t应发合计\t公积金\t\t保险\t\t其他扣除\t实发工资");for(i=0;i<customernum-1;i++)for(j=0;j<customernum-i-1;j++)if(customers[j].jx<=customers[j+1].jx){ms=customers[j];customers[j]=customers[j+1];customers[j+1]=ms;}for(i=0;i<customernum;i++)Customer(&customers[i]);}elseprintf("输入有误,按任意键返回菜单");} getchar();getchar();
}
//显示主菜单
void mainMenu()
{do{printf("\n\n\n 员工端");printf("\n 1.添加员工信息");printf("\n 2.显示员工列表");printf("\n 3.查找员工信息");printf("\n 4.退 出");printf("\n请选择1--4:");scanf("%c",&key);switch(key){case'1':add();break;case'2':list();break;case'3':seek();break;case'4':loop=0; break;default:printf("你输入的信息有误,请重新输入\n\n");}}while(loop);
}void mainmenu()
{do{printf("\n\n\n 管理员端");printf("\n 1.添加员工信息");printf("\n 2.修改员工信息");printf("\n 3.删除员工信息");printf("\n 4.显示员工列表");printf("\n 5.查找员工信息");printf("\n 6.员工信息排序");printf("\n 7.退 出");printf("\n请选择1--7:");scanf("%c",&key);switch(key){case'1':add();break;case'2':revise();break;case'3':Find();break;case'4':list();break;case'5':seek();break;case'6':paixu();break;case'7':loop=0; break;default:printf("你输入的信息有误,请重新输入\n\n");}}while(loop);}//主函数
void main(){//选择用户int i;printf("--------------------------------------------------------");printf("\n\t\t 欢迎来到员工工资管理系统\n");printf("--------------------------------------------------------");printf("\n\t\t 1.管理员模式\n");printf("\t\t 2.员工模式\n");printf("\t\t 3.退出系统\n");printf("请选择:");scanf("%d",&i);getchar();do{switch(i){case 1:mainmenu();break;case 2:mainMenu();break;case 3:loop=0;break;default:printf ("你输入的信息有误,请重新输入\n\n");}}while(loop);printf("你退出了系统");getchar();
}