职工工资管理系统源代码
员工工资管理系统源代码
#include<stdio.h>#include<string.h>typedef struct{int basic;//基本工资int position;//岗位工资int subsidy;//津贴int wages;//奖金int sum;//总工资}money;typedef struct{char num[20];//职工号char name[20];//姓名int age;//年龄char sex[20];//性别money salary;//工资}employee;int Print_jinru();//账号密码输入void Fscan_information();//“职工信息.txt”文件写入void Print_staff();//全体员工void Print_empl1(char x[51]);//按职工号查询void Print_empl2(char s[51]);//按姓名查询void Print_MainInterface();//主界面void Print_Interface_1();//职工信息录入界面void Print_Interface_2();//职工信息查询界面void Print_Interface_3();//职工工资排序界面void Print_Interface_4();//职工总工资void Print_Interface_5();//文件读出void qsort(int l,int r);//快速排序void Print_delete(int t);//删除职工信息void Print_Interface_2_1(int t);//职工信息修改界面int fyanzheng(char s1[],char s2[]);//密码验证函数employee st[500];//记录职工信息的函数int n;//职工总数void main(){int x;employee em;printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@\n");printf("@@@@ 欢迎使用员工工资管理系统@@@@\n");printf("@@@@ 制作人:刘爽@@@@\n");printf("@@@@在使用中产生的任何问题,欢迎进行批评指正@@@@\n");printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@\n");printf("\n");printf("\n");printf("\n");if (Print_jinru()){Fscan_information();Print_MainInterface();}else return;}void Fscan_information(){FILE *fp;int i;if ((fp=fopen("职工信息.txt","r"))==NULL){printf("cannot open this file\n");return ;}fscanf(fp,"%d",&n);for (i=1;i<=n;i++){fscanf(fp,"%s%s%d%s%d%d%d",st[i].num,st[i].name,&st[i].age,st[i].sex,&st[i].salary.basic,&s t[i].salary.subsidy,&st[i].salary.wages);st[i].salary.sum=st[i].salary.basic+st[i].salary.subsidy+st[i].salary.wages;}fclose(fp);}int fyanzheng(char s1[],char s2[]){FILE *fp1,*fp2;char str1[40]="",str2[40]="",st;int t;if ((fp1=fopen("账号验证.in","r"))==NULL){printf("cannot open this file\n");return 0;}t=0;st=fgetc(fp1);while (st!='#'){str1[t]=st;t++;st=fgetc(fp1);}if ((fp2=fopen("密码验证.in","r"))==NULL){printf("cannot open this file\n");return 0;}t=0;st=fgetc(fp2);while (st!='#'){str2[t]=st;t++;st=fgetc(fp2);}fclose(fp1);fclose(fp2);if ((strcmp(str1,s1)==0)&&(strcmp(str2,s2)==0)) return 1;elsereturn 0;}int Print_jinru(){int f,d;char x[20],y[20];f=0;d=0;while(1){printf("请输入账号:");scanf("%s",x);getchar();printf("请输入密码:");scanf("%s",y);getchar();f=fyanzheng(x,y);if (d>3)printf("错误次数太多,退出系统\n");return 0;}if (f>0) break;else{printf("账号或密码输入错误,请重新输入\n");d++;}}printf("\n");printf("欢迎进入员工工资管理系统\n");return 1;}void Print_MainInterface(){int x;printf("\n");printf("*************************华丽的分割线*************************\n");printf("\n");printf("1.职工信息录入\n");printf("2.职工信息查询\n");printf("3.职工工资排序\n");printf("4.统计职工总工资\n");printf("5.保存到文件\n");printf("6.退出职工工资系统\n");printf("请选择所需操作:");scanf("%d",&x);if (x==1)Print_Interface_1();elseif (x==2)Print_Interface_2();elseif (x==3)Print_Interface_3();elseif (x==4)Print_Interface_4();elseif (x==5)Print_Interface_5();else{printf(" ****** **** **** * * ***** * *\n");printf("* * * * * * * * * * *\n");printf("* * * * * * * * * * *\n");printf(" ****** ******** ******** ** * * * *\n");printf(" * * * ** * * * *\n");printf(" * * * ** * * * *\n");printf(" ****** **** **** ** ***** ***** \n");//printf("233333333333333333333333333333333333333333333333333333\n");return;}else{printf("输入命令错误,返回主菜单(再乱输入我找人打你啊)\n");Print_MainInterface();}}void Print_Interface_1(){n++;if (n>500){printf("超出职工最大数\n");Print_MainInterface();}printf("\n");printf("*************************妖精的分割线*************************\n");printf("\n");printf("新建职工号:");scanf("%s",st[n].num);printf("姓名:");scanf("%s",st[n].name);printf("年龄:");scanf("%d",&st[n].age);printf("性别:");scanf("%s",st[n].sex);printf("基本工资:");scanf("%d",&st[n].salary.basic);printf("津贴:");scanf("%d",&st[n].salary.subsidy);printf("奖金:");scanf("%d",&st[n].salary.wages);st[n].salary.sum=st[n].salary.basic+st[n].salary.subsidy+st[n].salary.wages;printf("职工信息已成功录入\n");Print_MainInterface();}void Print_Interface_2(){int x;char s[50],y[50];printf("\n");printf("*************************逗比的分割线*************************\n");printf("\n");printf("1.查询所有职工\n");printf("2.按职工号查询\n");printf("3.按职工姓名查询\n");printf("4.返回主菜单\n");printf("请选择查找方式:\n");scanf("%d",&x);if (x==1)Print_staff();elseif (x==2){printf("请输入职工工号:");scanf("%s",y);Print_empl1(y);}elseif (x==3){printf("请输入职工姓名:");scanf("%s",s);Print_empl2(s);}elseif (x==4)Print_MainInterface();else{printf("输入命令错误,返回上一层\n");Print_Interface_2();}}void Print_Interface_3(){char ch[10];printf("\n");qsort(1,n);printf("排序完成!排序后结果请从查询全体职工处查看\n");Print_MainInterface();}void Print_Interface_4(){int i,All=0;char ch[10];printf("\n");for (i=1;i<=n;i++)All=All+st[i].salary.sum;printf("所有职工的总工资为:%d\n",All);printf("请输入任意字符并敲回车键返回主菜单\n");scanf("%s",&ch);Print_MainInterface();}void Print_Interface_5(){FILE *fp;char ch[10];int i;if ((fp=fopen("职工信息.txt","w"))==NULL){printf("cannot open this file\n");return ;}fprintf(fp,"%d\n",n);for (i=1;i<=n;i++)fprintf(fp,"%s %s %d %s %d %d %d\n",st[i].num,st[i].name,st[i].age,st[i].sex,st[i].salary.basic, st[i].salary.subsidy,st[i].salary.wages);fclose(fp);printf("\n");printf("已保存到文件\n");printf("\n");printf("请输入任意字符返回主菜单\n");scanf("%s",&ch);Print_MainInterface();}void Print_staff(){int i;printf("\n");printf("*************************帅比的分割线*************************");printf("\n");for (i=1;i<=n;i++){printf("职工工号:%s\n",st[i].num);printf("姓名:%s\n",st[i].name);printf("年龄:%d\n",st[i].age);printf("性别:%s\n",st[i].sex);printf("基本工资:%d\n",st[i].salary.basic);printf("津贴:%d\n",st[i].salary.subsidy);printf("奖金:%d\n",st[i].salary.wages);printf("总工资:%d\n",st[i].salary.sum);printf("\n");}printf("返回上一层\n");Print_Interface_2();}void Print_empl1(char x[]){int i,t,y,d=0;printf("\n");for (i=1;i<=n;i++)if (strcmp(x,st[i].num)==0){t=i;d=1;printf("职工工号:%s\n",st[i].num);printf("姓名:%s\n",st[i].name);printf("年龄:%d\n",st[i].age);printf("性别:%s\n",st[i].sex);printf("基本工资:%d\n",st[i].salary.basic);printf("津贴:%d\n",st[i].salary.subsidy);printf("奖金:%d\n",st[i].salary.wages);printf("总工资:%d\n",st[i].salary.sum);printf("\n");break;}if (d>0){printf("如需删除请按2,修改请按1,返回请按0\n");scanf("%d",&y);if (y==2)Print_delete(t);elseif (y==1)Print_Interface_2_1(t);elseif (y==0)Print_Interface_2();else{printf("输入命令错误,返回上一层(再乱输入我找人打你啊)\n");Print_Interface_2();}}else{printf("对不起,查无此人(本系统不包括路人甲乙丙,不要乱输-_-!)\n");printf("请重新选择查询方式\n");Print_Interface_2();}}void Print_empl2(char s[]){int i,t,x,y=0;printf("\n");for (i=1;i<=n;i++)if (strcmp(s,st[i].name)==0){t=i;y=1;printf("职工工号:%s\n",st[i].num);printf("姓名:%s\n",st[i].name);printf("年龄:%d\n",st[i].age);printf("性别:%s\n",st[i].sex);printf("基本工资:%d\n",st[i].salary.basic);printf("津贴:%d\n",st[i].salary.subsidy);printf("奖金:%d\n",st[i].salary.wages);printf("总工资:%d\n",st[i].salary.sum);printf("\n");break;}if (y>0){printf("如需删除请按2,修改请按1,返回请按0(再乱输入我找人打你啊)\n");scanf("%d",&x);if (x==2)Print_delete(t);elseif (x==1)Print_Interface_2_1(t);elseif (x==0)Print_Interface_2();else{printf("输入命令错误,返回上一层\n");Print_Interface_2();}}else{printf("对不起,查无此人(本系统不包括路人甲乙丙,不要乱输-_-!)\n");printf("请重新选择查询方式\n");Print_Interface_2();}}void Print_delete(int t){st[t].salary.sum=0;qsort(1,n);n--;printf("已删除该职工并排序,自动返回主菜单\n");Print_MainInterface();}void Print_Interface_2_1(int t){int x;printf("\n");printf("请选择以下选项:\n");printf("1.职工号\n");printf("2.姓名\n");printf("3.年龄\n");printf("4.性别\n");printf("5.基本工资\n");printf("6.津贴\n");printf("7.奖金\n");printf("8.返回上一层\n");printf("9.返回主菜单\n");scanf("%d",&x);switch(x){case 1:scanf("%s",st[t].num);break;case 2:scanf("%s",st[t].name);break;case 3:scanf("%d",st[t].age);break;case 4:scanf("%s",st[t].sex);break;case 5:scanf("%s",st[t].salary.basic);break;case 6:scanf("%d",st[t].salary.subsidy);break;case 7:scanf("%d",st[t].salary.wages);break;}st[t].salary.sum=st[t].salary.basic+st[t].salary.subsidy+st[t].salary.wages;if (x<=8)Print_Interface_2();elseif (x==9)Print_MainInterface();}void qsort(int l,int r){int i,j,mid;employee tt;i=l;j=r;mid=st[(l+r)/2].salary.sum;do{while (st[i].salary.sum>mid) i++;while (st[j].salary.sum<mid) j--;if (i<=j){tt=st[i];st[i]=st[j];st[j]=tt;i++;j--;}}while(i<=j);if (i<r) qsort(i,r);if (l<j) qsort(l,j);。
c语言课程设计职工工资管理系统源代码
绝对可以完美运行,下面有运行图片#include<stdio.h> //调用库函数#include<string.h> //字符串处理#include<conio.h> //控制台输入输出#include<stdlib.h> //定义杂项函数及内存分配函数#define N 2 //宏定义以3代替N/******************************************************************************函数声明*******************************************************************************/ void enter();int menu();void input();void output();void search();void search_employeeid();void search_name();void edit();void array();void array_basesalary();void array_postwage();void array_totalwage();void statistics();void save();void load();/******************************************************************************职工类型定义*******************************************************************************/ struct employee{char employeeid[10];char name[10];char sex[10];int age;float basesalary;float postwage;float totalwage;};/******************************************************************************职工变量定义******************************************************************************/ struct employee emp[N];struct employee replace;struct employee *p=emp;/*****************************************************************************系统主函数******************************************************************************/ void main(){int c;while(1){printf(" \n\n\n\n");printf(" 欢迎进入职工工资管理系统\n\n\n");printf(" 1 进入管理系统\n\n");printf(" 0 退出\n\n");printf(" \n\n\n\n");printf(" 请输入你选择:\n");scanf("%d",&c);switch(c){case 1:enter();break;case 0:printf(" 谢谢使用!\n");exit(0);}}}/***************************************************************************** 功能:登陆函数,进行密码验证*****************************************************************************/ void enter(){char q;char key[10],password[10]="china";int k=1,i;printf(" 请输入密码:\n");for(i=0;i<5;i++){q=getch();key[i]=q;printf("*");}while(k<=3){if(strncmp(key,password,5)==0){while(1){int a;//system("cls");a=menu();switch(a){case 1:input();break;case 2:output();break;case 3:search();break;case 4:edit();break;case 5:array();break;case 6:load();statistics();break;case 0:printf("\n\n 谢谢使用!\n\n\n\n");save();exit(0);}}}else{k++;printf(" 输入密码错误!请再次输入:");for(i=0;i<5;i++){q=getch();key[i]=q;printf("*");}if(k>2){if(strncmp(password,key,5)==0)continue;else{printf(" 输入密码错误三次,系统将自动退出!\n");exit(0);}}}}}/************************************************************************功能: 主菜单函数参数:a类型:int说明: 变量返回值: a************************************************************************/int menu(){int a ;printf("\n\n");printf("|*****************欢迎进入职工工资管理系统************************|\n");printf("| |\n");printf("| |\n");printf("| 1 职工信息输入|\n");printf("| |\n");printf("| 2 职工信息输出|\n");printf("| |\n");printf("| 3 职工信息查询|\n");printf("| |\n");printf("| 4 职工信息修改|\n");printf("| |\n");printf("| 5 工资排序|\n");printf("| |\n");printf("| 6 工资统计|\n");printf("| |\n");printf("| 0 退出|\n");printf("| |\n");printf("| |\n");printf("|*****************************************************************|\n");printf("\n\n");printf(" 请输入你所选择的选项:");scanf("%d",&a);while(a>6||a<0){printf(" error!\n");printf(" 请重新输入你所选择的选项:");scanf("%d",&a);}return a;}/********************************************************************************* ***功能:职工信息输入********************************************************************************** ***/void input(){int c;p=emp;printf(" 进入职工信息输入模块\n\n\n");for(c=0;c<N;c++,p++){p[c].totalwage=p[c].basesalary+p[c].postwage;printf(" 请输入第%d个职工信息:\n\n",c+1);printf(" 请输入职工号:\n");scanf("%s",p->employeeid);if(strcmp(p->employeeid,"0")!=0){printf(" 请输入职工姓名:\n");scanf("%s",p->name);printf(" 请输入职工性别: \n");scanf("%s",&p->sex);printf(" 请输入职工年龄: \n");scanf("%d",&p->age);printf(" 请输入职工基本工资:\n");scanf("%f",&p->basesalary);printf(" 请输入职工岗位工资:\n");scanf("%f",&p->postwage);printf(" 职工信息输入完成!\n\n");}elsereturn;}save();}/******************************************************************************* 功能:职工信息输出********************************************************************************/ void output(){int j;load();p=emp;printf(" 进入职工信息输出模块\n\n\n");printf("-------------------------------------------------------------------------------\n");printf("| 职工号|姓名|性别|年龄|基本工资|岗位工资|总工资|\n");printf("-------------------------------------------------------------------------------\n");for(j=0;j<N;j++){p[j].totalwage=p[j].postwage+p[j].basesalary;printf("|%10s|%9s|%7s| %5d| %10.2f| %10.2f| %10.2f|\n",p[j].employeeid,p[j].name,p [j].sex,p[j].age,p[j].basesalary,p[j].postwage,p[j].totalwage);printf("-------------------------------------------------------------------------------\n");}printf("\n\n 职工信息输出完成!\n\n");getchar();}/******************************************************************************功能:职工信息查询******************************************************************************/ void search(){int j;while(1){printf("*********************职工信息查询*********************\n\n\n");printf(" 1 按职工号查询\n");printf(" 2 按职工姓名查询\n");printf(" 0 退出该项操作\n");printf("\n\n");while(1){printf(" 请输入你的选择\n");scanf("%d",&j);if(j>=0&&j<=2){switch(j){case 1:search_employeeid();break;case 2:search_name();break;case 0:return;}}else{printf(" 输入错误!\n\n");printf(" 请再次输入你的选择: \n\n");}}}}/******************************************************************************* 功能:按职工号查询函数*******************************************************************************/ void search_employeeid(){char employeeid[10];int k,j;p=emp;printf("*********************按职工号查询职工信息*****************************\n\n\n\n");printf(" 请输入要查询职工的职工号:\n\n");scanf("%s",employeeid);for(k=0;k<N;k++){if(strcmp(employeeid,p->employeeid)==0){j=k;p[j].totalwage=p[j].postwage+p[j].basesalary;printf("-------------------------------------------------------------------------------\n");printf("| 职工号|姓名|性别|年龄|基本工资|岗位工资|总工资|\n");printf("|%10s|%9s|%7s| %5d| %10.2f| %10.2f| %10.2f|\n",p[j].employeeid,p[j].name,p [j].sex,p[j].age,p[j].basesalary,p[j].postwage,p[j].totalwage);printf("-------------------------------------------------------------------------------\n");break;}else{printf(" not found\n");return;}}}/*****************************************************************************功能:按职工姓名查询函数*****************************************************************************/ void search_name(){char name[10];int flog=0;int f,j;p=emp;printf("******************************按职工姓名查询职工信息***********************\n\n\n");printf(" 请输入要查询职工的姓名:\n\n");scanf("%s",name);for(f=0;f<N;f++,p++){if(strcmp(name,p->name)==0){j=f;p[j].totalwage=p[j].postwage+p[j].basesalary;printf("-------------------------------------------------------------------------------\n");printf("| 职工号|姓名|性别|年龄|基本工资|岗位工资|总工资|\n");printf("|%10s|%9s|%7s| %5d| %10.2f| %10.2f| %10.2f|\n",p[j].employeeid,p[j].name,p [j].sex,p[j].age,p[j].basesalary,p[j].postwage,p[j].totalwage);printf("-------------------------------------------------------------------------------\n");break;}else{printf(" not found \n\n");return;}}getchar();}/*******************************************************************************功能:职工信息修改函数*******************************************************************************/ void edit(){char e[10];int g=0,j;char flog;p=emp;printf(" 请输入你要修改职工的职工号:\n");scanf("%s",e);for(g=0;g<N;g++){// if(*e==p[g].employeeid)if(strcmp(e,p->employeeid)==0){j=g;p[j].totalwage=p[j].postwage+p[j].basesalary;printf("-------------------------------------------------------------------------------\n");printf("| 职工号|姓名|性别|年龄|基本工资|岗位工资|总工资|\n");printf("|%10s|%9s|%7s| %5d| %10.2f| %10.2f| %10.2f|\n",p[j].employeeid,p[j].name,p[j].sex ,p[j].age,p[j].basesalary,p[j].postwage,p[j].totalwage);printf("-------------------------------------------------------------------------------\n");printf(" 是否要修改该职工信息?y(是)or n(否)?\n\n");getchar();scanf("%c",&flog);if(flog == 'y'){printf(" 请输入新姓名:\n");scanf("%s",p->name);printf(" 请输入性别:\n");scanf("%s",&p->sex);printf(" 请输入年龄:\n");scanf("%d",&p->age);printf(" 请输入基本工资:\n");scanf("%f",&p->basesalary);printf(" 请输入岗位工资:\n");scanf("%f",&p->postwage);printf(" 修改职工信息成功!\n\n");}if(flog == 'n'){printf(" 退出该项操作!\n\n");return;}save();}if(g==N){printf(" not found \n\n\n");return;}}}/************************************************************************ 功能:职工工资排列函数************************************************************************/ void array(){int j;while(1){printf("*************************工资排序*********************\n\n");printf(" 1 按基本工资排序\n\n");printf(" 2 按岗位工资排序\n\n");printf(" 3 按总工资排列\n\n");printf(" 0 退出\n\n");printf("\n\n\n");while(1){printf(" 请输入你的选择:\n\n");scanf("%d",&j);if(j>=0&&j<=3){switch(j){case 1:array_basesalary();break;case 2:array_postwage();break;case 3:array_totalwage();break;case 0:return;}}else{printf(" 输入错误!\n\n\n");printf(" 请再次输入你的选择:\n\n");}}}}/**************************************************************************功能:按基本工资排列(选择法)***************************************************************************/void array_basesalary(){int i,j,k;p=emp;for(i=0;i<N-1;i++){k=i;for(j=i+1;j<N;j++){if(p[k].basesalary<p[j].basesalary)k=j;}if(k!=i){replace=emp[k];emp[k]=emp[i];emp[i]=replace;}}for(j=0;j<N;j++){p[j].totalwage=p[j].postwage+p[j].basesalary;printf("-------------------------------------------------------------------------------\n");printf("| 职工号|姓名|性别|年龄|基本工资|岗位工资|总工资|\n");printf("|%10s|%9s|%7s| %5d| %10.2f| %10.2f| %10.2f|\n",p[j].employeeid,p[j].name,p [j].sex,p[j].age,p[j].basesalary,p[j].postwage,p[j].totalwage);}printf("-------------------------------------------------------------------------------\n");}/************************************************************************功能:按岗位工资排列(冒泡法)*************************************************************************/void array_postwage(){int i,j;p=emp;for(i=0;i<N;i++){for(j=0;j<N-i;j++){if(p[j].postwage<p[j+1].postwage){replace=emp[j];emp[j]=emp[j+1];emp[j+1]=replace;}}}for(j=0;j<N;j++){p[j].totalwage=p[j].postwage+p[j].basesalary;printf("------------------------------------------------------------------------------\n");printf("| 职工号|姓名|性别|年龄|基本工资|岗位工资|总工资|\n");printf("|%10s|%9s|%7s| %5d| %10.2f| %10.2f| %10.2f|\n",p[j].employeeid,p[j].name,p [j].sex,p[j].age,p[j].basesalary,p[j].postwage,p[j].totalwage);}printf("-------------------------------------------------------------------------------\n");}/************************************************************************功能:按总工资排列(插入法)************************************************************************/void array_totalwage(){int i,j;p=emp;for(i=1;i<N;i++){replace=emp[i];for(j=i-1;j>=0&&p[i].totalwage>p[i].totalwage;j--){emp[j+1]=emp[j];emp[j+1]=replace;}}for(j=N-1;j>=0;j--){p[j].totalwage=p[j].postwage+p[j].basesalary;printf("-------------------------------------------------------------------------------\n");printf("| 职工号|姓名|性别| 年龄|基本工资|岗位工资|总工资|\n");printf("|%10s|%9s|%7s| %5d| %10.2f| %10.2f| %10.2f|\n",p[j].employeeid,p[j].name,p [j].sex,p[j].age,p[j].basesalary,p[j].postwage,p[j].totalwage);}printf("-------------------------------------------------------------------------------\n");}/*************************************************************************功能:工资统计函数**************************************************************************/void statistics(){int z,a=0,b=0,c=0;p=emp;for(z=0;z<N;z++){if(p[z].totalwage>3000){a++;continue;}if(p[z].totalwage>=2000&&p[z].totalwage<=3000){b++;continue;}if(p[z].totalwage<=2000&&p[z].totalwage>0){c++;continue;}}printf(" 总工资在3000元以上的职工人数有:%d\n\n",a);printf(" 总工资在2000元至3000元的职工人数有:%d\n\n",b);printf(" 总工资在2000元以下的职工人数有:%d\n\n",c);getchar();}/*************************************************************************** 功能:导出函数***************************************************************************/ void save(){int k;FILE *fp;p=emp;if((fp=fopen("emp_list","wb"))==NULL){printf(" Create file error!\n");return;}for(k=0;k<N;k++,p++){if(fwrite(p,sizeof(struct employee),1,fp)!=1){printf(" file save error!\n\n");break;}elsecontinue;}getchar();fclose(fp);}/***********************************************************************功能:导入函数***********************************************************************/ void load(){int l;FILE *fp;p=emp;if((fp=fopen("emp_list","rb"))==NULL){printf(" Create file error!\n");exit(0);}for(l=0;l<N;l++,p++){if(fread(p,sizeof(struct employee),1,fp)!=1){printf(" file read error!\n\n");break;}elsecontinue;}getchar();fclose(fp);}下面是实验结果。
小型公司工资管理系统C源代码
#include<iomanip.h>#include<iostream.h>#include<fstream.h>#include<stdlib.h>class Employ//基类-雇员类{protected:int num;char name[10];char sex;int age;int wage;public:virtual void set()=0;virtual void print()=0;virtual void reserved()=0;};class Manager:public Employ//经理类{public:void set();void print();void reserved();};class Salesman:public Employ//销售员类{protected:int salesvolume;int snum;public:void set();void print();void reserved();void printinfor();int getsales(){return salesvolume;}int getsnum(){return snum;}};class MarketMan:public Manager//销售经理类{protected:int salesvolume;public:void set();void print();void reserved();int resetwage();{return num;}char*getname(){return name;}int getamount(Salesman s[],int n){salesvolume=0;for(int i=0;i<n;i++){if(s[i].getsnum()==num)salesvolume+=s[i].getsales();}return salesvolume;}};class Technician:public Employ//技术员类{protected:int worktime;public:void set();void print();void reserved();};void Manager::set(){cout<<"经理旳编号:";cin>>num;cout<<"其姓名:";cin>>name;cout<<"性别(m/w):";cin>>sex;cout<<"年龄:";cin>>age;}void Manager::print()//经理类组员函数{cout<<"┣━━━━━━╋━━━━━━╋━━━━━━╋━━━━━━╋━━━━━━┫"<<endl;cout<<"┃"<<setw(12)<<num<<"┃"<<setw(12)<<name<<"┃"<<setw(12)<<sex;cout<<"┃"<<setw(12)<<age<<"┃"<<setw(12)<<wage<<"┃"<<endl;}void Manager::reserved(){ofstream employf("E:\\05-29\\gzglxt.txt",ios::app);employf<<"经理旳编号:"<<num<<endl<<"其姓名:"<<name<<endl<<"性别(m/w):"<<sex<<endl<<"年龄:"<<age<<endl;}void MarketMan::set(){wage=resetwage();cout<<"销售经理旳编号:";cin>>num;cout<<"其姓名:";cin>>name;cout<<"性别(m/w):";cin>>sex;cout<<"年龄:";cin>>age;}void MarketMan::print(){resetwage();cout<<"┣━━━━━━╋━━━━━━╋━━━━━━╋━━━━━━╋━━━━━━┫"<<endl;cout<<"┃"<<setw(12)<<num<<"┃"<<setw(12)<<name<<"┃"<<setw(12)<<sex;cout<<"┃"<<setw(12)<<age<<"┃"<<setw(12)<<wage<<"┃"<<endl;}void MarketMan::reserved(){ofstream employf("E:\\05-29\\gzglxt.txt",ios::app);employf<<"销售经理旳编号:"<<num<<endl<<"其姓名:"<<name<<endl<<"性别(m/w):"<<sex<<endl<<"年龄:"<<age<<endl;}int MarketMan::resetwage(){wage=5000+int(salesvolume*0.005); return wage;}void Salesman::set()//销售员类定义{cout<<"销售员旳编号:";cin>>num;cout<<"其姓名:";cin>>name;cout<<"性别(m/w):";cin>>sex;cout<<"年龄:";cin>>age;cout<<"销售额:";cin>>salesvolume;cout<<"所属销售经理旳编号:"; cin>>snum;wage=int(salesvolume*0.04);}void Salesman::printinfor(){cout<<"┣━━━━━━━╋━━━━━━━╋━━━━━━━┫"<<endl;cout<<"┃"<<setw(14)<<num<<"┃"<<setw(14)<<name<<"┃"<<setw(14)<<salesvolume<<"┃"<<endl;}void Salesman::print(){cout<<"┣━━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━━━┫"<<endl;cout<<"┃"<<setw(8)<<num<<"┃"<<setw(10)<<name<<"┃"<<setw(10)<<sex;cout<<"┃"<<setw(10)<<age<<"┃"<<setw(10)<<wage<<"┃"<<setw(16)<<getsnum()<<"┃"<<endl;}void Salesman::reserved(){ofstream employf("E:\\05-29\\gzglxt.txt",ios::app);employf<<"销售员旳编号:"<<num<<endl<<"其姓名:"<<name<<endl<<"性别(m/w):"<<sex<<endl<<"年龄:"<<age<<endl<<"销售额:"<<salesvolume<<endl<<"所属销售经理旳编号"<<snum<<endl;}void Technician::set()//技术员类定义{cout<<"技术员旳编号:";cin>>num;cout<<"其姓名:";cin>>name;cout<<"性别(m/w):";cin>>sex;cout<<"年龄:";cin>>age;cout<<"工作时间:";cin>>worktime;wage=worktime*100;}void Technician::print(){cout<<"┣━━━━━━╋━━━━━━╋━━━━━━╋━━━━━━╋━━━━━━┫"<<endl;cout<<"┃"<<setw(12)<<num<<"┃"<<setw(12)<<name<<"┃"<<setw(12)<<sex;cout<<"┃"<<setw(12)<<age<<"┃"<<setw(12)<<wage<<"┃"<<endl;}void Technician::reserved(){ofstream employf("E:\\05-29\\gzglxt.txt",ios::app);employf<<"技术员旳编号:"<<num<<endl<<"其姓名:"<<name<<endl<<"性别(m/w):"<<sex<<endl<<"年龄:"<<age<<endl<<"工作时间:"<<worktime<<endl;}//主函数int t,m,s,mm;Technician*pt;Manager*pm;Salesman*ps;MarketMan*pmm;void setin();void count();void printdata();void reservedall();void single();void main(){cout<<"请分别输入技术员, 经理, 销售员, 销售经理人数:"<<endl; cin>>t>>m>>s>>mm;pt=new Technician[t];pm=new Manager[m];ps=new Salesman[s];pmm=new MarketMan[mm];if((!pt)||(!pm)||(!ps)||(!pmm)){cout<<"堆内存分派失败!"<<endl;exit(1);}single();}void single(){cout<<"★★小型企业工资管理系统★★"<<endl; cout<<"┏━━━━━━━━━━━━━┓"<<endl; cout<<"┃请选择所需旳操作┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃数据输入:1,并按回车键┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃数据记录:2,并按回车键┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃数据打印:3,并按回车键┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃数据备份:4,并按回车键┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃退出系统:5,并按回车键┃"<<endl; cout<<"┃┃"<<endl; cout<<"┗━━━━━━━━━━━━━┛"<<endl; cout<<"请选择一种操作:"<<endl;int choice;cin>>choice;switch(choice){case 1:setin();case 2:count();case 3:printdata();case 4:reservedall();case 5:exit(0);}}void setin(){Menu1:cout<<"★★小型企业工资管理系统★★"<<endl;cout<<"┏━━━━━━━━━━━━━━━━┓"<<endl; cout<<"┃请选择所需旳操作┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃技术员数据输入: 1,并按回车键┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃经理数据输入: 2,并按回车键┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃销售员数据输入: 3,并按回车键┃"<<endl;cout<<"┃┃"<<endl; cout<<"┃销售经理数据输入: 4,并按回车键┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃返回上一级菜单: 5,并按回车键┃"<<endl; cout<<"┗━━━━━━━━━━━━━━━━┛"<<endl; cout<<"请选择一种操作";int ch1,i;cin>>ch1;switch(ch1){case 1:{for(i=0;i<t;i++)pt[i].set();cout<<"---------------------------------"<<endl;goto Menu1;}case 2:{for(i=0;i<m;i++)pm[i].set();cout<<"---------------------------------"<<endl;goto Menu1;}case 3:{for(i=0;i<s;i++)ps[i].set();cout<<"---------------------------------"<<endl;goto Menu1;}case 4:{for(i=0;i<mm;i++)pmm[i].set();cout<<"---------------------------------"<<endl;goto Menu1;}case 5:single();}}void count(){Menu2:cout<<"★★小型企业工资管理系统★★"<<endl;cout<<"┏━━━━━━━━━━━━━━━━━━━━━━┓"<<endl;cout<<"┃请选择所需旳操作┃"<<endl;cout<<"┃┃"<<endl;cout<<"┃各销售经理下属销售员业绩记录: 1,并按回车键┃"<<endl;cout<<"┃┃"<<endl;cout<<"┃销售经理按工资排序: 2,并按回车键┃"<<endl;cout<<"┃┃"<<endl;cout<<"┃返回上一级菜单: 3,并按回车键┃"<<endl;cout<<"┗━━━━━━━━━━━━━━━━━━━━━━┛"<<endl;cout<<"请选择一种操作";int ch2,i,j;cin>>ch2;switch(ch2){case 1:{for(i=0;i<mm;i++){cout<<"职工号为:"<<pmm[i].getnum()<<"销售经理:"<<pmm[i].getname()<<"下属销售员旳业绩为:"<<endl;cout<<"┏━━━━━━━┳━━━━━━━┳━━━━━━━┓"<<endl;cout<<"┃职工号┃姓名┃销售额┃"<<endl;for(j=0;j<s;j++)if(pmm[i].getnum()==ps[j].getsnum())ps[j].printinfor();cout<<"┣━━━━━━━┻━━━┳━━━┻━━━━━━━┫"<<endl;cout<<"┃销售额总计: ┃"<<setw(22)<<pmm[i].getamount(ps,s)<<"┃"<<endl;cout<<"┗━━━━━━━━━━━┻━━━━━━━━━━━┛"<<endl;}goto Menu2;}case 2:{cout<<"销售经理按工资排序为:"<<endl;MarketMan pmmm;for(i=1;i<mm;i++)for(j=0;j<mm-i;j++)if(pmm[j].getamount(ps,s)<pmm[j+1].getamount(ps,s)){pmmm=pmm[j];pmm[j]=pmm[j+1];pmm[j+1]=pmmm;}cout<<"┏━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━┓"<<endl;cout<<"┃职工号┃姓名┃性别┃年龄┃工资┃"<<endl;for(i=0;i<mm;i++)pmm[i].print();cout<<"┗━━━━━━┻━━━━━━┻━━━━━━┻━━━━━━┻━━━━━━┛"<<endl;cout<<" --------------------------------------------"<<endl;goto Menu2;}case 3:single();}}void printdata(){Menu3:cout<<"★★小型企业工资管理系统★★"<<endl;cout<<"┏━━━━━━━━━━━━━━━━┓"<<endl;cout<<"┃请选择所需旳操作┃"<<endl;cout<<"┃┃"<<endl;cout<<"┃技术员数据输出: 1,并按回车键┃"<<endl;cout<<"┃┃"<<endl;cout<<"┃经理数据输出: 2,并按回车键┃"<<endl;cout<<"┃┃"<<endl;cout<<"┃销售员数据输出: 3,并按回车键┃"<<endl;cout<<"┃┃"<<endl;cout<<"┃销售经理数据输出: 4,并按回车键┃"<<endl;cout<<"┃┃"<<endl;cout<<"┃返回上一级: 5,并按回车键┃"<<endl;cout<<"┗━━━━━━━━━━━━━━━━┛"<<endl;cout<<"请选择一种操作";int ch3,i;cin>>ch3;switch(ch3){case 1:{cout<<"技术员"<<endl<<endl;cout<<"┏━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━┓"<<endl;cout<<"┃职工号┃姓名┃性别┃年龄┃工资┃"<<endl;for(i=0;i<t;i++)pt[i].print();cout<<"┗━━━━━━┻━━━━━━┻━━━━━━┻━━━━━━┻━━━━━━┛"<<endl;cout<<"------------------------------------------"<<endl;goto Menu3;}case 2:{ cout<<"经理"<<endl<<endl;cout<<"┏━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━┓"<<endl;cout<<"┃职工号┃姓名┃性别┃年龄┃工资┃"<<endl;for(i=0;i<m;i++)pm[i].print();cout<<"┗━━━━━━┻━━━━━━┻━━━━━━┻━━━━━━┻━━━━━━┛"<<endl;cout<<"------------------------------------------"<<endl;goto Menu3;}case 4:{cout<<"销售经理"<<endl<<endl;cout<<"┏━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━┓"<<endl;cout<<"┃职工号┃姓名┃性别┃年龄┃工资┃"<<endl;for(i=0;i<mm;i++)pmm[i].print();cout<<"┗━━━━━━┻━━━━━━┻━━━━━━┻━━━━━━┻━━━━━━┛"<<endl;cout<<"------------------------------------------"<<endl;goto Menu3;}case 3:{cout<<"销售员"<<endl<<endl;cout<<"┏━━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━━━┓"<<endl;cout<<"┃职工号┃姓名┃性别┃年龄┃工资┃所属部门经理编号┃"<<endl;for(i=0;i<s;i++)ps[i].print();cout<<"┗━━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━━━┛"<<endl;cout<<"------------------------------------------"<<endl;goto Menu3;}case 5:single();}}void reservedall(){Menu4:cout<<"★★小型企业工资管理系统★★"<<endl;cout<<"┏━━━━━━━━━━━━━━━━┓"<<endl; cout<<"┃请选择所需旳操作┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃技术员数据备份: 1,并按回车键┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃经理数据备份: 2,并按回车键┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃销售员数据备份: 3,并按回车键┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃销售经理数据备份: 4,并按回车键┃"<<endl; cout<<"┃┃"<<endl; cout<<"┃返回上一级: 5,并按回车键┃"<<endl; cout<<"┗━━━━━━━━━━━━━━━━┛"<<endl; cout<<"请选择一种操作";int ch4,i;cin>>ch4;switch(ch4){case 1:{for(i=0;i<t;i++)pt[i].reserved();goto Menu4;}case 2:{for(i=0;i<m;i++)pm[i].reserved();goto Menu4;}case 3:{for(i=0;i<s;i++)ps[i].reserved();goto Menu4;}case 4:{for(i=0;i<mm;i++) pmm[i].reserved();goto Menu4;}case 5:single();}}。
员工工资管理系统源代码
#include<stdio.h>#include<string.h> typedefstruct {int basic;// 基本工资int position;// 岗位工资int subsidy;// 津贴intwages;// 奖金int sum;// 总工资}money;typedef struct{char num[20];// 职工号char name[20];// 姓名int age;// 年龄charsex[20];// 性别moneysalary;// 工资}employee;int Print_jinru();// 账号密码输入void Fscan_information();// “职工信息.txt ”文件写入void Print_staff();// 全体员工void Print_empl1(char x[51]);// 按职工号查询void Print_empl2(char s[51]);// 按姓名查询void Print_MainInterface();// 主界面void Print_Interface_1();// 职工信息录入界面void Print_Interface_2();// 职工信息查询界面void Print_Interface_3();// 职工工资排序界面void Print_Interface_4();// 职工总工资void Print_Interface_5();// 文件读出void qsort(int l,int r);// 快速排序voidPrint_delete(int t);// 删除职工信息void Print_Interface_2_1(int t);// 职工信息修改界面int fyanzheng(char s1[],char s2[]);// 密码验证函数employee st[500];// 记录职工信息的函数int n;// 职工总数void main(){int x;employee em;printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@\n");printf("@@@@ 欢迎使用员工工资管理系统@@@@\n");printf("@@@@ 制作人:刘爽@@@@\n");printf("@@@@ 在使用中产生的任何问题,欢迎进行批评指正@@@@\n");printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@\n");printf("\n");printf("\n");printf("\n");if (Print_jinru()){Fscan_information();Print_MainInterface();}else return;}void Fscan_information(){FILE *fp;int i;if ((fp=fopen(" 职工信息.txt","r"))==NULL){printf("cannot open this file\n");return ;}fscanf(fp,"%d",&n);for (i=1;i<=n;i++){fscanf(fp,"%s%s%d%s%d%d%d",st[i].num,st[i].name,&st[i].age,st[i].sex,&st[i].salary.basic,&s t[i].salary.subsidy,&st[i].salary.wages);st[i].salary.sum=st[i].salary.basic+st[i].salary.subsidy+st[i].salary.wages;}fclose(fp);}int fyanzheng(char s1[],char s2[]){FILE *fp1,*fp2;char str1[40]="",str2[40]="",st;int t;if ((fp1=fopen(" 账号验证.in","r"))==NULL){printf("cannot open this file\n");return 0;} t=0;st=fgetc(fp1);while (st!='#'){str1[t]=st;t++;st=fgetc(fp1);}if ((fp2=fopen(" 密码验证.in","r"))==NULL){printf("cannot open this file\n");return 0;}t=0;st=fgetc(fp2);while (st!='#'){str2[t]=st;t++;st=fgetc(fp2);}fclose(fp1);fclose(fp2);if ((strcmp(str1,s1)==0)&&(strcmp(str2,s2)==0)) return 1;elsereturn 0;}int Print_jinru(){int f,d;char x[20],y[20];f=0;d=0;while(1){printf(" 请输入账号:"); scanf("%s",x); getchar();printf(" 请输入密码:"); scanf("%s",y); getchar();f=fyanzheng(x,y);if (d>3)printf(" 错误次数太多,退出系统 \n");return 0;}if (f>0) break;else{printf(" 账号或密码输入错误,请重新输入 \n"); d++;}}printf("\n");printf(" 欢迎进入员工工资管理系统!!!\n");return 1;}else void Print_MainInterface(){int x;printf("\n");printf(" *************************printf("\n");printf("1. 职工信息录入 \n");printf("2. 职工信息查询 \n");printf("3. 职工工资排序 \n");printf("4. 统计职工总工资 \n");printf("5. 保存到文件 \n");printf("6. 退出职工工资系统 \n");printf(" 请选择所需操作 :");scanf("%d",&x);if (x==1)Print_Interface_1();elseif (x==2)Print_Interface_2();elseif (x==3)Print_Interface_3();elseif (x==4)Print_Interface_4();elseif (x==5)Print_Interface_5();华丽的分割线 *********************** **\n");if (x==6){printf(" ******printf("*printf("*printf(" ****** printf(" printf(" printf(" ****** ******** ************ ********************** ******\n");*\n");*\n");*\n");*\n");*\n");\n");printf("233333333333333333333333333333333333333333333333333333\n"); return;} else{printf(" 输入命令错误,返回主菜单 (再乱输入我找人打你啊 )\n");Print_MainInterface(); }}void Print_Interface_1(){n++;if (n>500){printf(" 超出职工最大数 \n");Print_MainInterface();} printf("\n");printf(" ************************* printf("\n");printf(" 新建职工号 :");scanf("%s",st[n].num);printf(" 姓名 :"); scanf("%s",st[n].name);printf(" 年龄 :"); scanf("%d",&st[n].age);printf(" 性别 :"); scanf("%s",st[n].sex);printf(" 基本工资 :"); scanf("%d",&st[n].salary.basic);printf(" 津贴 :"); scanf("%d",&st[n].salary.subsidy);printf(" 奖金 :"); scanf("%d",&st[n].salary.wages);st[n].salary.sum=st[n].salary.basic+st[n].salary.subsidy+st[n].salary.wages; // 妖精的分割线 *************************\n");printf(" 职工信息已成功录入\n");Print_MainInterface();}void Print_Interface_2(){int x;char s[50],y[50];printf("\n");printf(" ************************* 逗比的分割线*********************** **\n");printf("\n");printf("1. 查询所有职工\n");printf("2. 按职工号查询\n"); printf("3. 按职工姓名查询\n");printf("4. 返回主菜单\n"); printf(" 请选择查找方式:\n");scanf("%d",&x);if (x==1)Print_staff();elseif (x==2){printf(" 请输入职工工号:"); scanf("%s",y);Print_empl1(y);}elseif (x==3){printf(" 请输入职工姓名:"); scanf("%s",s);Print_empl2(s);}elseif (x==4)Print_MainInterface();else{printf(" 输入命令错误,返回上一层\n"); Print_Interface_2();}}void Print_Interface_3(){char ch[10];printf("\n");qsort(1,n);printf(" 排序完成!排序后结果请从查询全体职工处查看\n");Print_MainInterface();}void Print_Interface_4(){int i,All=0;char ch[10];printf("\n");for (i=1;i<=n;i++)All=All+st[i].salary.sum;printf(" 所有职工的总工资为:%d\n",All);printf(" 请输入任意字符并敲回车键返回主菜单\n");scanf("%s",&ch);Print_MainInterface();}void Print_Interface_5(){FILE *fp;char ch[10];int i;if ((fp=fopen(" 职工信息.txt","w"))==NULL){printf("cannot open this file\n");return ;}fprintf(fp,"%d\n",n);for (i=1;i<=n;i++)fprintf(fp,"%s %s %d %s %d %d %d\n",st[i].num,st[i].name,st[i].age,st[i].sex,st[i].salary.basic, st[i].salary.subsidy,st[i].salary.wages);fclose(fp);printf("\n");printf(" 已保存到文件\n");printf("\n");printf(" 请输入任意字符返回主菜单\n");scanf("%s",&ch);Print_MainInterface();}void Print_staff(){int i;printf("\n");printf(" ************************* 帅比的分割线*************************" );printf("\n");for (i=1;i<=n;i++){printf(" 职工工号:%s\n",st[i].num);printf(" 姓名:%s\n",st[i].name);printf(" 年龄:%d\n",st[i].age);printf(" 性别:%s\n",st[i].sex);printf(" 基本工资:%d\n",st[i].salary.basic);printf(" 津贴:%d\n",st[i].salary.subsidy);printf(" 奖金:%d\n",st[i].salary.wages);printf(" 总工资:%d\n",st[i].salary.sum); printf("\n");}printf(" 返回上一层\n");Print_Interface_2();}void Print_empl1(char x[]) {int i,t,y,d=0;printf("\n");for (i=1;i<=n;i++)if (strcmp(x,st[i].num)==0) { t=i;d=1;printf(" 职工工号:%s\n",st[i].num);printf(" 姓名:%s\n",st[i].name);printf(" 年龄:%d\n",st[i].age);printf(" 性别:%s\n",st[i].sex);printf(" 基本工资:%d\n",st[i].salary.basic);printf(" 津贴:%d\n",st[i].salary.subsidy); printf(" 奖金:%d\n",st[i].salary.wages);printf(" 总工资:%d\n",st[i].salary.sum); printf("\n");break;}if (d>0){printf(" 如需删除请按2,修改请按1,返回请按0\n"); scanf("%d",&y);if (y==2)Print_delete(t);else if (y==1)Print_Interface_2_1(t);else if (y==0) Print_Interface_2();else{printf(" 输入命令错误,返回上一层(再乱输入我找人打你啊)\n");Print_Interface_2();}}else{printf(" 对不起,查无此人(本系统不包括路人甲乙丙,不要乱输-_-! )\n");printf(" 请重新选择查询方式\n");Print_Interface_2();}}void Print_empl2(char s[]){int i,t,x,y=0;printf("\n");for (i=1;i<=n;i++)if (strcmp(s,st[i].name)==0){t=i;y=1;printf(" 职工工号:%s\n",st[i].num);printf(" 姓名:%s\n",st[i].name);printf(" 年龄:%d\n",st[i].age);printf(" 性别:%s\n",st[i].sex);printf(" 基本工资:%d\n",st[i].salary.basic);printf(" 津贴:%d\n",st[i].salary.subsidy);printf(" 奖金:%d\n",st[i].salary.wages);printf(" 总工资:%d\n",st[i].salary.sum);printf("\n");break;}if (y>0){printf(" 如需删除请按2,修改请按1,返回请按0(再乱输入我找人打你啊)\n");scanf("%d",&x);if (x==2)Print_delete(t);elseif (x==1) Print_Interface_2_1(t);else if (x==0) Print_Interface_2();else{ printf(" 输入命令错误,返回上一层\n"); Print_Interface_2();}}else{printf(" 对不起,查无此人(本系统不包括路人甲乙丙,不要乱输-_-! )\n");printf(" 请重新选择查询方式\n");Print_Interface_2();}}void Print_delete(int t){st[t].salary.sum=0;qsort(1,n);n--;printf(" 已删除该职工并排序,自动返回主菜单\n");Print_MainInterface();}void Print_Interface_2_1(int t){int x;printf("\n");printf(" 请选择以下选项:\n");printf("1. 职工号\n");printf("2. 姓名\n");printf("3. 年龄\n");printf("4. 性别\n");printf("5. 基本工资\n");printf("6. 津贴\n");printf("7. 奖金\n");printf("8. 返回上一层\n");printf("9. 返回主菜单\n");scanf("%d",&x);switch(x){case 1:scanf("%s",st[t].num);break;case 2: scanf("%s",st[t].name);break;case 3: scanf("%d",st[t].age);break;case 4: scanf("%s",st[t].sex);break;case 5: scanf("%s",st[t].salary.basic);break;case 6: scanf("%d",st[t].salary.subsidy);break;case 7: scanf("%d",st[t].salary.wages);break;} st[t].salary.sum=st[t].salary.basic+st[t].salary.subsidy+st[t].salary.wages;if (x<=8)Print_Interface_2();elseif (x==9) Print_MainInterface();}void qsort(int l,int r){int i,j,mid;employee tt;i=l;j=r;mid=st[(l+r)/2].salary.sum;do{while (st[i].salary.sum>mid) i++;while (st[j].salary.sum<mid) j--;if (i<=j){tt=st[i];st[i]=st[j];st[j]=tt;i++;j--;}}while(i<=j);if (i<r) qsort(i,r);if (l<j) qsort(l,j);。
工资管理系统毕业设计附源码
工资管理系统毕业设计附源码工资管理系统是一种用于管理和计算员工工资的软件系统。
它可以帮助企业自动化工资计算、发放和记录,提高工资管理的效率和准确性。
下面是一个简单的工资管理系统的毕业设计附源码的示例。
首先,我们需要设计数据库来存储员工信息和工资数据。
可以使用关系型数据库如MySQL或SQLite。
以下是一个简化的员工表和工资表的设计示例:员工表(employees):employee_id: 员工ID(主键)。
name: 员工姓名。
department: 所属部门。
position: 职位。
工资表(salaries):salary_id: 工资记录ID(主键)。
employee_id: 员工ID(外键)。
salary_date: 工资发放日期。
basic_salary: 基本工资。
bonus: 奖金。
deductions: 扣款。
total_salary: 总工资。
接下来,我们需要开发一个用户界面,让管理员可以输入员工信息和工资数据,并进行工资计算和管理。
可以使用Java编程语言和Swing图形用户界面库来实现。
以下是一个简单的Java代码示例:java.import javax.swing.;import java.awt.;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class SalaryManagementSystem extends JFrame {。
// 声明界面组件。
private JTextField idField, nameField, departmentField, positionField;private JTextField dateField, basicSalaryField, bonusField, deductionsField;private JTextArea resultArea;private JButton calculateButton, saveButton;public SalaryManagementSystem() {。
c语言课程实践《职工工资管理系统》源代码
fprintf(report,"\n\tAverage wage\t\t%.2f\t\t0.00\t\t%.2f",(float)(fsum/fn),(float)(fsum/fn));//如果男性人数是0,则只输出女性的平均工资
else
fprintf(report,"\n\tAverage wage\t\t%.2f\t\t%.2f\t\t%.2f",(float)(fsum/fn),(float)(msum/mn),(float)((fsum+msum)/(fn+mn)));//如果男女都不为0的话,那么则把平均工资都输出
p=temp;//temp指针变量往后移
temp=temp->next;//temp指针变量往后移
}
if(fnum==temp->num)//如果找到了,就执行下面的程序
{
find=1;//标记变量:find是1的时候说明找到,0则说明没找到
printf("\n");
unsigned int age; // 年龄
unsigned long telephone,wage,num; // 电话,工资,编号
struct workers *next; // 指向下一条记录的指针(链表使用)
};
struct workers *head,*bottom,*temp,*p;//定义指向结构体的指针变量
insert();//调用创建链表,录入信息的函数
}
getchar();//输入任意字符
return main();//返回主调函数
}
员工工资管理系统代码
scanf("%s",employee.shi);
fseek (fp,0,SEEK_END); /*移动文件内部位置指针*/
fwrite(&employee,sizeof(EmployeeType),1,fp); /*将员工信息存入文件中*/
tag=tolower(tag); /*大写字母转化为小写字母*/
}
} while(tag=='y'); /*肯定回答时循环*/
}
fseek(fp,-sizeof(EmployeeType),SEEK_CUR); /*移动文件内部位置指针*/
fwrite(&employee,sizeof(EmployeeType),1,fp); /*输入数据*/
}break;
case 2: /*按员工姓名查询*/
printf("输入员工的姓名:\n");
scanf("%s",name);
rewind (fp); /*使指针位置返回到文件的开头*/
void ListDate(void); /*显示数据*/
void Pack(void); /*在物理上删除作有标记的记录*/
#endif
FILE *fp;
void AddData(void) /*增添数据*/
&& employee.status==0
)break;
fread (&employee,sizeof(EmployeeType),1,fp);
}
if(!feof(fp))
{ /*查询成功*/
职工工资管理源代码
附录〈源程序〉include <stdio.h>include <stdlib.h>include <string.h>struct worker{char name30;char ID10;int salary1;salary2;salary3;};int dqstruct worker wo;void show;void bcstruct worker wo;void add;void see;void search;void ghcz;void xmcz;void del;void xmsc;void ghsc;void statistics;void modify;void ghxg;void xmxg;void reserve;void back;void author;struct worker wo100; //保存所有的职工信息int Number=0; //记录总的职工人数void main{int choose=0;whiletrue{show;printf"\t\t====>请选择:";scanf"%d";&choose;system"cls";switchchoose{case 0: exit0;//退出break;case 1: add;back;//添加职工信息break;case 2: see;back;//查看职工信息break;case 3: search; back;// 查找职工信息break;case 4: del;back;//删除职工信息break;case 5: statistics; back;//统计职工工资break;case 6: modify; back;//修改职工信息break;case 7:reserve; back;//保存数据break;case 8:author; back;//作者信息break;default:break;}fflushstdin;getchar;system"cls";}}int dqstruct worker wo{FILE fp=NULL;int i=0;whilefread&woi;sizeofstruct worker;1;fp i++;fclosefp;return i;}void show{printf"\n";printf"\t职工工资管理系统\n\n";printf"\t☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n\n"; printf"\t^^^^^^^^^^^^^^^1 添加职工信息^^^^^^^^^^^^^^^^^\n"; printf"\t^^^^^^^^^^^^^^^2 查看职工信息^^^^^^^^^^^^^^^^^\n"; printf"\t^^^^^^^^^^^^^^^3 查找职工信息^^^^^^^^^^^^^^^^^\n"; printf"\t^^^^^^^^^^^^^^^4 删除职工信息^^^^^^^^^^^^^^^^^\n"; printf"\t^^^^^^^^^^^^^^^5 统计职工工资^^^^^^^^^^^^^^^^^\n"; printf"\t^^^^^^^^^^^^^^^6 修改职工信息^^^^^^^^^^^^^^^^^\n"; printf"\t^^^^^^^^^^^^^^^7 保存数据^^^^^^^^^^^^^^^^^\n"; printf"\t^^^^^^^^^^^^^^^8 作者信息^^^^^^^^^^^^^^^^^\n"; printf"\t^^^^^^^^^^^^^^^0 退出系统^^^^^^^^^^^^^^^^^\n\n"; printf"\t★★★★★★★★★★★★★★★★★★★★★★★\n"; }void bcstruct worker wo{FILE fp=NULL;fwritewo;sizeofstruct worker;1;fp;fclosefp;}//添加职工信息void add{int numberTemp=0;int i=0;struct worker temp;printf"请输入要添加职工个数:"; scanf"%d";&numberTemp;fori=0;i<numberTemp;i++{printf"输入第%d个职工信息\n";i+1; printf"姓名:";scanf"%s";;printf"工号:";scanf"%s";temp.ID;printf"基本工资:";scanf"%d";&temp.salary1;printf"职务工资:";scanf"%d";&temp.salary2;printf"津贴:";scanf"%d";&temp.salary3; woNumber++=temp; //写入到数组bc&temp; //写入到文件}printf"添加成功\n";}//查看职工信息void see{int i=0;printf"以下是全部职工\n";printf"\t姓名\t工号\t基本工资\t职务工资\t津贴\n";whilei<Number{printf"\t%s\t%s\t%d\t\t%d\t\t%d\n";;woi.ID;woi.salary1; woi.salary2;woi.salary3;i++;}}//查找职工信息void search{int n=0;printf"1 按姓名查找\n";printf"2 按工号查找\n";scanf"%d";&n;switchn{case 1: xmcz;break;case 2: ghcz;break;default: printf"输入错误\n";break;}}void xmcz//按姓名查找{char name30;int i=0;printf"请输入要查找职工姓名:";scanf"%s";name;system"cls";printf"\t姓名\t工号\t基本工资\t职务工资\t津贴\n";for i=0;i<Number;i++{if strcmpname;==0{printf"\t%s\t%s\t%d\t\t%d\t\t%d\n";;woi.ID;woi.salary1; woi.salary2;woi.salary3;}}void ghcz//按工号查找{char id10;int i=0;printf"请输入要查找职工工号:";scanf"%s";id;system"cls";printf"\t姓名\t工号\t基本工资\t职务工资\t津贴\n";for i=0;i<Number;i++{if strcmpid;woi.ID==0{printf"\t%s\t%s\t%d\t\t%d\t\t%d\n";;woi.ID;woi.salary1; woi.salary2;woi.salary3;}}}//删除职工信息void delint n=0;printf"1 按姓名删除\n";printf"2 按工号删除\n";scanf"%d";&n;switchn{case 1: xmsc;break;case 2: ghsc;break;}}void xmsc//按姓名删除{FILE fp=NULL;char name30;int i=0;int j=0;printf"请输入要删除的职工姓名:"; scanf"%s";name;fori=0;i<Number;i++{if strcmpname;==0{for j=i;j<Number-1;j++{woj=woj+1;}Number--;}}//将剩余数据写入文件擦除以前的数据for i=0;i<Number;i++{fwrite&woi;sizeofstruct worker;1;fp; }fclosefp;printf"删除成功;\n";}void ghsc//按工号删除{FILE fp=NULL;char id60;int i=0;int j=0;printf"请输入要删除的职工工号:"; scanf"%s";id;fori=0;i<Number;i++{if strcmpid;woi.ID==0{for j=i;j<Number-1;j++{woj=woj+1;}Number--;}}//将剩余数据写入文件擦除以前的数据for i=0;i<Number;i++{fwrite&woi;sizeofstruct worker;1;fp; }fclosefp;printf"删除成功;\n";}//统计职工工资void statistics{int i=0;double s=0.0;double sum100;fori=0;i<Number;i++{sumi=woi.salary1+woi.salary2+woi.salary3; printf"%s的总工资为:%f\n";;sumi; }fori=0;i<Number;i++{s+=sumi;}printf"平均工资为:%f\n";s/Number;}//修改职工信息void modify{int mode=0;printf"请选择修改查找方式\n"; printf"1 按姓名查找修改\n"; printf"2 按工号查找修改\n"; scanf"%d";&mode;switchmode{case 1: xmxg;break;case 2: ghxg;break;default: printf"输入错误\n"; break;}}void xmxg//按姓名修改{FILE fp=NULL;char name30;int i=0;printf"请输入要修改的职工姓名:"; scanf"%s";name;for i=0;i<Number;i++{if strcmpname;;elsebreak;}printf"\t姓名\t工号\t基本工资\t职务工资\t津贴\n";printf"\t%s\t%s\t%d\t\t%d\t\t%d\n";;woi.ID;woi.salary1; woi.salary2;woi.salary3;printf"请重新输入该职工信息";printf"姓名:";scanf"%s";;printf"工号:";scanf"%s";woi.ID;printf"基本工资:";scanf"%d";&woi.salary1;printf"职务工资:";scanf"%d";&woi.salary2;printf"津贴:";scanf"%d";&woi.salary3;//信息修改后重新更新文件里面的数据以保持数据一致性for i=0;i<Number;i++{fwrite&woi;sizeofstruct worker;1;fp;}fclosefp;}void ghxg//按工号修改{FILE fp=NULL;char id30;int i=0;printf"请输入要修改的职工工号:";scanf"%s";id;for i=0;i<Number;i++{if strcmpid;woi.ID;elsebreak;}printf"\t姓名\t工号\t基本工资\t职务工资\t津贴\n";printf"\t%s\t%s\t%d\t\t%d\t\t%d\n";;woi.ID;woi.salary1; woi.salary2;woi.salary3;printf"请重新输入该职工信息";printf"姓名:";printf"姓名:";scanf"%s";;printf"工号:";scanf"%s";woi.ID;printf"基本工资:";scanf"%d";&woi.salary1;printf"职务工资:";scanf"%d";&woi.salary2;printf"津贴:";scanf"%d";&woi.salary3;//信息修改后重新更新文件里面的数据以保持数据一致性for i=0;i<Number;i++{fwrite&woi;sizeofstruct worker;1;fp;}fclosefp;printf"\t=======>修改成功\n";}//保存数据void reserve{printf"\t=====程序在运行时已自动保存.....\n";}void back{printf"\t===>按Enter键返回主菜单\n";}//作者信息void author{printf"\t☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n\n"; printf"\t^^^^^^^^^^^^^^^学校名称^^^^^^^^^^^^^\n\n"; printf"\t^^^^^^^^^^^^^^学院班级^^^^^^^^^^^^^\n\n"; printf"\t^^^^^^^^^^^^^^^XXX制作^^^^^^^^^^^^^\n\n"; printf"\t★★★★★★★★★★★★★★★★\n\n";。
企业职工工资管理系统_附代码(DOC32页)
#include <stdio.h>#include <string.h> #include <stdlib.h>#define E 50void Creat();void Creat2();void Creat3();void Chakan();void Chakan2();void Chakan3();void add();void del();void xiugai();void findnum();void findname(); void findname2(); void findshijian(); void gengxin();void findtime();void jisuan();void jisuan2();void jisuan3();void pai();void put();int number;float sum;struct employee{char num[5];char name[10];char sex[3];char shengri[10];char degree[10];int nianxian; } emp[E];struct emp_kao{char num[5];char name[10];char riqi[10];int tianshu;}emp_kaoqin[E];struct emp_gong{char num[5];char name[10];floatzhiwugongzi,zhiwubutie,zhufangbutie,kaoqin,yingfagongzi,yanglaobaoxian,zhufang,shifagongzi; }emp_gongzi[E];void main (){char YN[3];char *Y="Y";char *N="N";int i;int LL;//put();printf(" ********企业职工工资管理系统********\n");kaishi: printf("\n创建文件(请选【1】)\n 操作文件(请选【2】)\n 查看文件(请选【3】)\n 更新文件(请选【4】)\n");scanf("%d",&LL);if(LL==1){Creat();printf("\n创建考勤记录文件??Y/N(注意大写)\n");scanf("%s",&YN);if (strcmp(YN,Y) == 0){Creat2();printf("\n创建工资信息文件??Y/N(注意大写)\n");scanf("%s",&YN);if (strcmp(YN,Y) == 0){Creat3();goto kaishi;}else{goto kaishi;}}else{goto kaishi;}}else if (LL==2){caozuo: printf("增加人事基本信息(请选【1】)\n");printf("删除人事基本信息(请选【2】)\n");printf("修改人事基本信息(请选【3】)\n");printf("查询人事基本信息(请选【4】)\n");printf("输出某月份的职工工资信息(请选【5】)\n");printf("职工工资信息进行统计(请选【6】)\n");printf("退出(请选【7】)\n");scanf("%d",&LL);if (LL==1){add();goto caozuo;}else if (LL==2){shanchu :del();printf(" 是否继续删除??(注意大写)\n");scanf("%s",&YN);if (strcmp(YN,Y) == 0){goto shanchu;}else if (strcmp(YN,N) == 0){goto caozuo;}else{printf("操作错误!!返回->\n");goto caozuo;}}else if (LL==3){xiugai:xiugai();printf(" 是否继续修改??(注意大写)\n");scanf("%s",&YN);if (strcmp(YN,Y) == 0){goto xiugai;}else if (strcmp(YN,N) == 0){goto caozuo;}else{printf("操作错误!!返回->\n");goto caozuo;}}else if (LL==4){chaxun: printf("编号查询(请选【1】)\n 全名查询(请选【2】)\n 姓查询(请选【3】)\n 月份查询(请选【4】)\n 退出(请选【5】)\n\n");scanf("%d",&LL);if (LL==1){findnum();goto chaxun;}if (LL==2){findname();goto chaxun;}if (LL==3){findname2();goto chaxun;}if (LL==4){findtime();goto chaxun;}if(LL==5){goto caozuo;}else{printf("操作错误!!返回->\n");goto caozuo;}}if(LL==5){findshijian();goto caozuo;}if (LL==6){jisuan: printf("职工人数...(请选【1】)\n 平均实发工资(请选【2】)\n低于平均工资(请选【3】)\n 退出(请选【4】)\n");scanf("%d",&LL);if (LL==1){jisuan();goto jisuan;}else if (LL==2){jisuan2();goto jisuan;}else if (LL==3){jisuan3();goto jisuan;}else if (LL==4){goto caozuo;}else{printf("操作错误!!返回->\n");goto jisuan;}}if (LL==7){goto kaishi;}}else if(LL==3){chakan: printf("\n查看基本信息文件(请选【1】)\n查看考勤记录文件(请选【2】)\n查看工资信息文件(请选【3】)\n退出(请选【4】)\n");scanf("%d",&LL);if (LL==1){Chakan();goto chakan;}else if(LL==2){Chakan2();goto chakan;}else if(LL==3){Chakan3();goto chakan;}else if(LL==4){goto kaishi;}else{printf("操作错误!!返回->\n");goto chakan;}}else if (LL==4){gengxin();goto kaishi;}int aa;scanf("%d",&aa);}void Creat(){FILE *fp;int i,j;printf("创建【一】基本信息文件.....\n");printf(" 请您输入创建人数:");scanf("%d",&number);if ((fp = fopen("number.dat", "wb+")) == NULL){printf("Can't open file\n");exit(0);}fwrite(&number,sizeof(int),1,fp);fclose(fp);if ((fp = fopen("employee.dat", "wb+")) == NULL){printf("Can't open file\n");exit(0);}printf(" 编号姓名性别出生日期职称工作年限\n");for (i=0;i<number;i++){j=i+1;printf("->【%d】",j);scanf(" %s %s %s %s %s %d",emp[i].num,emp[i].name,emp[i].sex,emp[i].sh engri,emp[i].degree,&emp[i].nianxian);printf("\n");}pai();fwrite(emp,sizeof(struct employee),number, fp);fclose(fp);if ((fp = fopen("employee.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}printf(" 创建成功!!\n");printf(" 编号姓名性别出生日期职称工作年限\n");for (i = 0; fread(&emp[i],sizeof(struct employee),1,fp) == 1 ; i++){printf(" %s %s %s %s %s %d\n",emp[i].num,emp[i].name,emp[i].s ex,emp[i].shengri,emp[i].degree,emp[i].nianxian);}fclose(fp);}void Creat2(){FILE *fp,*fp2;int i,j;printf("创建【二】考勤记录文件.....\n");printf(" 目前需创建人数:%d\n",number);printf(" 编号姓名日期出勤次数\n",number);if ((fp = fopen("employee.dat", "rb")) == NULL){printf("Can't open file\n");exit(0);}fread(emp,sizeof(struct employee),number, fp);if ((fp2 = fopen("emp_kao.dat", "wb")) == NULL){printf("Can't open file\n");exit(0);}for (i=0;i<number;i++){j=i+1;strcpy(emp_kaoqin[i].name, emp[i].name);strcpy(emp_kaoqin[i].num, emp[i].num);printf("->【%d】%s %s",j,emp_kaoqin[i].num,emp_kaoqin[i].name);scanf(" %s %d",emp_kaoqin[i].riqi,&emp_kaoqin[i].tianshu);printf("\n");}fwrite(emp_kaoqin, sizeof(struct emp_kao),number, fp2);fclose(fp);fclose(fp2);if ((fp = fopen("emp_kao.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}printf(" 创建成功!!\n");printf(" 编号姓名日期出勤天数\n");for (i = 0; fread(&emp_kaoqin[i],sizeof(struct emp_kao),1,fp) == 1 ; i++){printf(" %s %s %s %d\n",emp_kaoqin[i].num,emp_kaoqin[i].name,emp_ka oqin[i].riqi,emp_kaoqin[i].tianshu);}fclose(fp);}void Creat3(){FILE *fp,*fp2,*fp3;int i,j;char *zhugong="助工";char *gongchengshi="工程师";char *gaojigongchengshi="高级工程师";floatzhiwugongzi,zhiwubutie,zhufangbutie,kaoqin,yingfagongzi,yanglaobaoxian,zhufang,shifagongzi;printf("创建【三】工资信息文件.....\n");printf(" 共创建人数:%d\n",number);if ((fp = fopen("employee.dat", "rb")) == NULL){printf("Can't open file\n");exit(0);}fread(emp,sizeof(struct employee),number, fp);if ((fp2 = fopen("emp_kao.dat", "rb")) == NULL){printf("Can't open file\n");exit(0);}fread(emp_kaoqin,sizeof(struct emp_kao),number, fp2);if ((fp3 = fopen("emp_gong.dat", "wb")) == NULL){printf("Can't open file\n");exit(0);}for (i=0;i<number;i++){j=i+1;strcpy(emp_gongzi[i].name, emp[i].name);strcpy(emp_gongzi[i].num, emp[i].num);floatzhiwugongzi,zhiwubutie,zhufangbutie,kaoqin,yingfagongzi,yanglaobaoxian,zhufang,shifagongzi; if (strcmp(emp[i].degree,zhugong) == 0){zhiwugongzi=720*(1+(emp[i].nianxian*2)/100);zhiwubutie=zhiwugongzi*25/100;zhufangbutie=(zhiwugongzi+zhiwubutie)*25/100;if (emp_kaoqin[i].tianshu>=20){kaoqin=10*emp_kaoqin[i].tianshu;}else if ((emp_kaoqin[i].tianshu>=10)&&(emp_kaoqin[i].tianshu<20)){kaoqin=5*emp_kaoqin[i].tianshu;}else{kaoqin=0;}yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie+kaoqin;yanglaobaoxian=(zhiwugongzi+zhiwubutie)*0.1;zhufang=yingfagongzi*0.05;shifagongzi=yingfagongzi-yanglaobaoxian-zhufang;emp_gongzi[i].zhiwugongzi=zhiwugongzi;emp_gongzi[i].zhiwubutie=zhufangbutie;emp_gongzi[i].zhufangbutie=zhufangbutie;emp_gongzi[i].kaoqin=kaoqin;emp_gongzi[i].yingfagongzi=yingfagongzi;emp_gongzi[i].yanglaobaoxian=yanglaobaoxian;emp_gongzi[i].zhufang=zhufang;emp_gongzi[i].shifagongzi=shifagongzi;}if (strcmp(emp[i].degree,gongchengshi) == 0){zhiwugongzi=960*(1+(emp[i].nianxian*3)/100);zhiwubutie=zhiwugongzi*25/100;zhufangbutie=(zhiwugongzi+zhiwubutie)*25/100;if (emp_kaoqin[i].tianshu>=20){kaoqin=10*emp_kaoqin[i].tianshu;}else if ((emp_kaoqin[i].tianshu>=10)&&(emp_kaoqin[i].tianshu<20)) {kaoqin=5*emp_kaoqin[i].tianshu;}else{kaoqin=0;}yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie+kaoqin;yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie+kaoqin;yanglaobaoxian=(zhiwugongzi+zhiwubutie)*0.1;zhufang=yingfagongzi*0.05;shifagongzi=yingfagongzi-yanglaobaoxian-zhufang;emp_gongzi[i].zhiwugongzi=zhiwugongzi;emp_gongzi[i].zhiwubutie=zhufangbutie;emp_gongzi[i].zhufangbutie=zhufangbutie;emp_gongzi[i].kaoqin=kaoqin;emp_gongzi[i].yingfagongzi=yingfagongzi;emp_gongzi[i].yanglaobaoxian=yanglaobaoxian;emp_gongzi[i].zhufang=zhufang;emp_gongzi[i].shifagongzi=shifagongzi;}if (strcmp(emp[i].degree,gaojigongchengshi) == 0){zhiwugongzi=1350*(1+(emp[i].nianxian*5)/100);zhiwubutie=zhiwugongzi*25/100;zhufangbutie=(zhiwugongzi+zhiwubutie)*25/100;if (emp_kaoqin[i].tianshu>=20){kaoqin=10*emp_kaoqin[i].tianshu;}else if ((emp_kaoqin[i].tianshu>=10)&&(emp_kaoqin[i].tianshu<20)) {kaoqin=5*emp_kaoqin[i].tianshu;}else{kaoqin=0;}yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie+kaoqin;yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie+kaoqin;yanglaobaoxian=(zhiwugongzi+zhiwubutie)*0.1;zhufang=yingfagongzi*0.05;shifagongzi=yingfagongzi-yanglaobaoxian-zhufang;emp_gongzi[i].zhiwugongzi=zhiwugongzi;emp_gongzi[i].zhiwubutie=zhufangbutie;emp_gongzi[i].zhufangbutie=zhufangbutie;emp_gongzi[i].kaoqin=kaoqin;emp_gongzi[i].yingfagongzi=yingfagongzi;emp_gongzi[i].yanglaobaoxian=yanglaobaoxian;emp_gongzi[i].zhufang=zhufang;emp_gongzi[i].shifagongzi=shifagongzi;}printf("\n");}fwrite(emp_gongzi, sizeof(struct emp_gong),number, fp3);fclose(fp);fclose(fp2);fclose(fp3);if ((fp = fopen("emp_gong.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}printf(" 自动创建成功!!\n\n\n");for (i = 0; fread(&emp_gongzi[i],sizeof(struct emp_gong),1,fp) == 1 ; i++){printf("编号%s 姓名%s 职务工资%f 职务补贴%f 住房补贴%f\n考勤管理奖%f 应发工资%f 养老保险%f 住房公积金%f 实发工资%f\n",emp_gongzi[i].num,emp_gongzi[i].name,emp_gongzi[i].zhiwugongzi,emp_gongzi[i].zhiwubutie, emp_gongzi[i].zhufangbutie,emp_gongzi[i].kaoqin,emp_gongzi[i].yingfagongzi,emp_gongzi[i].yanglaobaoxian,emp_gongzi[i].zhufang,emp_gongzi[i].shifagongzi);printf("\n\n\n");}fclose(fp);}void pai(){int i,j;int t;char temp[10];for (i=0;i<number;i++){for (j=i+1;j<number;j++){if (strcmp(emp[i].num,emp[j].num)>0){strcpy(temp, emp[i].num);strcpy(emp[i].num,emp[j].num);strcpy( emp[j].num,temp);strcpy(temp, emp[i].name);strcpy(emp[i].name,emp[j].name);strcpy(emp[j].name,temp);strcpy(temp, emp[i].sex);strcpy(emp[i].sex,emp[j].sex);strcpy( emp[j].sex,temp);strcpy(temp, emp[i].shengri);strcpy(emp[i].shengri,emp[j].shengri);strcpy( emp[j].shengri,temp);strcpy(temp, emp[i].degree);strcpy(emp[i].degree,emp[j].degree);strcpy( emp[j].degree,temp);t=emp[i].nianxian;emp[i].nianxian=emp[j].nianxian;emp[j].nianxian=t;}}}}void put(){printf(" ********企业职工工资管理系统********\n");printf("创建:\n【一】基本信息文件\n【二】考勤记录文件(每个月1份)\n【三】工资信息文件(每个月1份)\n");printf("操作:\n");printf("【1】增加人事基本信息|\n");printf("【2】删除人事基本信息|\n");printf("【3】修改人事基本信息|\n");printf("【4】查询人事基本信息|\n");printf("【5】输出某月份的职工的工资信息|\n");printf("【6】职工工资信息进行统计|\n");}void Chakan(){FILE *fp;int i;if ((fp = fopen("employee.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}printf(" 查看成功!!\n");printf(" 编号姓名性别出生日期职称工作年限\n");for (i = 0; fread(&emp[i],sizeof(struct employee),1,fp) == 1 ; i++){printf(" %s %s %s %s %s %d\n",emp[i].num,emp[i].name,emp[i].s ex,emp[i].shengri,emp[i].degree,emp[i].nianxian);}fclose(fp);//goto chakan;}void Chakan2(){FILE *fp;int i;char name[15];printf("请您输入要查看的考勤文件:\n");scanf("%s",name);if ((fp = fopen(name, "rb+")) == NULL){printf("Can't open file\n");exit(0);}printf(" 查看成功!!\n");printf(" 编号姓名日期出勤天数\n");for (i = 0; fread(&emp_kaoqin[i],sizeof(struct emp_kao),1,fp) == 1 ; i++){printf(" %s %s %s %d\n",emp_kaoqin[i].num,emp_kaoqin[i].name,emp_ka oqin[i].riqi,emp_kaoqin[i].tianshu);}fclose(fp);//goto chakan;}void Chakan3(){FILE *fp;int i;char name[15];printf("请您输入要查看的工资文件:\n");scanf("%s",name);if ((fp = fopen(name, "rb+")) == NULL){printf("Can't open file\n");exit(0);}printf(" 查看成功!!\n");for (i = 0; fread(&emp_gongzi[i],sizeof(struct emp_gong),1,fp) == 1 ; i++){printf("编号%s 姓名%s 职务工资%f 职务补贴%f 住房补贴%f\n考勤管理奖%f 应发工资%f 养老保险%f 住房公积金%f 实发工资%f\n",emp_gongzi[i].num,emp_gongzi[i].name,emp_gongzi[i].zhiwugongzi,emp_gongzi[i].zhiwubutie,emp_gongzi[i].zhufangbutie,emp_gongzi[i].kaoqin,emp_gongzi[i].yingfagongzi,emp_gongzi[i].yanglaobaoxian, emp_gongzi[i].zhufang,emp_gongzi[i].shifagongzi);printf("\n\n\n");}fclose(fp);//goto chakan;}void add(){FILE *fp;int i;if ((fp = fopen("number.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);fread(&number,sizeof(int),1,fp);fclose(fp);if ((fp = fopen("employee.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}fread(emp,sizeof(struct employee),number,fp);fclose(fp);if ((fp = fopen("employee.dat", "wb+")) == NULL){printf("Can't open file\n");exit(0);}printf("编号姓名性别出生日期职称工作年限\n");scanf(" %s %s %s %s %s %d",emp[number].num,emp[number].name,emp[n umber].sex,emp[number].shengri,emp[number].degree,&emp[number].nianxian);number++;pai();fwrite(emp,sizeof(struct employee),number, fp);fclose(fp);if ((fp = fopen("number.dat", "wb+")) == NULL){printf("Can't open file\n");exit(0);}fwrite(&number,sizeof(int),1,fp);fclose(fp);if ((fp = fopen("employee.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}printf(" 添加成功!!\n");printf(" 编号姓名性别出生日期职称工作年限\n");for (i = 0; fread(&emp[i],sizeof(struct employee),1,fp) == 1 ; i++)printf(" %s %s %s %s %s %d\n",emp[i].num,emp[i].name,emp[i].s ex,emp[i].shengri,emp[i].degree,emp[i].nianxian);}fclose(fp);}void del(){FILE *fp;int i;char num[5];if ((fp = fopen("number.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}fread(&number,sizeof(int),1,fp);fclose(fp);if ((fp = fopen("employee.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}fread(emp,sizeof(struct employee),number,fp);fclose(fp);if ((fp = fopen("employee.dat", "wb+")) == NULL){printf("Can't open file\n");exit(0);}printf("请您输入编号:\n");scanf("%s",num);for (i=0;i<number;i++){if (strcmp(num, emp[i].num) != 0){fwrite(&emp[i], sizeof(struct employee), 1, fp);}number--;fclose(fp);if ((fp = fopen("number.dat", "wb+")) == NULL){printf("Can't open file\n");exit(0);}fwrite(&number,sizeof(int),1,fp);fclose(fp);if ((fp = fopen("employee.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}printf(" 删除成功!!\n");printf(" 编号姓名性别出生日期职称工作年限\n");for (i = 0; fread(&emp[i],sizeof(struct employee),1,fp) == 1 ; i++){printf(" %s %s %s %s %s %d\n",emp[i].num,emp[i].name,emp[i].s ex,emp[i].shengri,emp[i].degree,emp[i].nianxian);}fclose(fp);}void xiugai(){FILE *fp;int i;char num[5];int flag=1;if ((fp = fopen("number.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}fread(&number,sizeof(int),1,fp);fclose(fp);if ((fp = fopen("employee.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}fread(emp,sizeof(struct employee),number,fp);fclose(fp);if ((fp = fopen("employee.dat", "wb+")) == NULL){printf("Can't open file\n");exit(0);}printf("请您输入编号:\n");scanf("%s",num);for (i=0;i<number;i++){if (strcmp(num,emp[i].num)==0){printf("搜索到!!请您修改:\n");printf("职称:现任年限:\n");scanf("%s %d",emp[i].degree,&emp[i].nianxian);flag=2;}}fwrite(emp, sizeof(struct employee), number, fp);fclose(fp);if(flag==2){if ((fp = fopen("employee.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}printf(" 修改成功!!\n");printf(" 编号姓名性别出生日期职称工作年限\n");for (i = 0; fread(&emp[i],sizeof(struct employee),1,fp) == 1 ; i++){printf(" %s %s %s %s %s %d\n",emp[i].num,emp[i].name,emp[i].s ex,emp[i].shengri,emp[i].degree,emp[i].nianxian);}fclose(fp);}else{printf("该信息不存在\n");}}void gengxin(){char nian[15];char nian2[15];FILE *fp,*fp2,*fp3;int i,j;printf("更新考勤记录文件.....\n");printf(" 请输入年月(k.dat):\n");scanf("%s",nian);printf(" 编号姓名日期出勤次数\n",number);if ((fp = fopen("number.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}fread(&number,sizeof(int),1,fp);fclose(fp);if ((fp = fopen("employee.dat", "rb")) == NULL){printf("Can't open file\n");exit(0);}fread(emp,sizeof(struct employee),number, fp);if ((fp2 = fopen(nian, "wb")) == NULL){printf("Can't open file\n");exit(0);}for (i=0;i<number;i++){j=i+1;strcpy(emp_kaoqin[i].name, emp[i].name);strcpy(emp_kaoqin[i].num, emp[i].num);printf("->【%d】%s %s",j,emp_kaoqin[i].num,emp_kaoqin[i].name);scanf(" %s %d",emp_kaoqin[i].riqi,&emp_kaoqin[i].tianshu);printf("\n");}fwrite(emp_kaoqin, sizeof(struct emp_kao),number, fp2);fclose(fp);fclose(fp2);if ((fp = fopen(nian, "rb+")) == NULL){printf("Can't open file\n");exit(0);}printf("更新成功!!\n");printf(" 编号姓名日期出勤天数\n");for (i = 0; fread(&emp_kaoqin[i],sizeof(struct emp_kao),1,fp) == 1 ; i++){printf(" %s %s %s %d\n",emp_kaoqin[i].num,emp_kaoqin[i].name,emp_ka oqin[i].riqi,emp_kaoqin[i].tianshu);}fclose(fp);printf("更新工资文件.....\n");printf(" 请输入年月(g.dat):\n");scanf("%s",nian);char *zhugong="助工";char *gongchengshi="工程师";char *gaojigongchengshi="高级工程师";floatzhiwugongzi,zhiwubutie,zhufangbutie,kaoqin,yingfagongzi,yanglaobaoxian,zhufang,shifagongzi;if ((fp = fopen("employee.dat", "rb")) == NULL){printf("Can't open file\n");exit(0);}fread(emp,sizeof(struct employee),number, fp);if ((fp2 = fopen("emp_kao.dat", "rb")) == NULL){printf("Can't open file\n");exit(0);}fread(emp_kaoqin,sizeof(struct emp_kao),number, fp2);if ((fp3 = fopen(nian, "wb")) == NULL){printf("Can't open file\n");exit(0);}for (i=0;i<number;i++){j=i+1;strcpy(emp_gongzi[i].name, emp[i].name);strcpy(emp_gongzi[i].num, emp[i].num);floatzhiwugongzi,zhiwubutie,zhufangbutie,kaoqin,yingfagongzi,yanglaobaoxian,zhufang,shifagongzi;if (strcmp(emp[i].degree,zhugong) == 0){zhiwugongzi=720*(1+(emp[i].nianxian*2)/100);zhiwubutie=zhiwugongzi*25/100;zhufangbutie=(zhiwugongzi+zhiwubutie)*25/100;if (emp_kaoqin[i].tianshu>=20){kaoqin=10*emp_kaoqin[i].tianshu;}else if ((emp_kaoqin[i].tianshu>=10)&&(emp_kaoqin[i].tianshu<20)){kaoqin=5*emp_kaoqin[i].tianshu;}else{kaoqin=0;}yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie+kaoqin;yanglaobaoxian=(zhiwugongzi+zhiwubutie)*0.1;zhufang=yingfagongzi*0.05;shifagongzi=yingfagongzi-yanglaobaoxian-zhufang;emp_gongzi[i].zhiwugongzi=zhiwugongzi;emp_gongzi[i].zhiwubutie=zhufangbutie;emp_gongzi[i].zhufangbutie=zhufangbutie;emp_gongzi[i].kaoqin=kaoqin;emp_gongzi[i].yingfagongzi=yingfagongzi;emp_gongzi[i].yanglaobaoxian=yanglaobaoxian;emp_gongzi[i].zhufang=zhufang;emp_gongzi[i].shifagongzi=shifagongzi;}if (strcmp(emp[i].degree,gongchengshi) == 0){zhiwugongzi=960*(1+(emp[i].nianxian*3)/100);zhiwubutie=zhiwugongzi*25/100;zhufangbutie=(zhiwugongzi+zhiwubutie)*25/100;if (emp_kaoqin[i].tianshu>=20){kaoqin=10*emp_kaoqin[i].tianshu;}else if ((emp_kaoqin[i].tianshu>=10)&&(emp_kaoqin[i].tianshu<20)) {kaoqin=5*emp_kaoqin[i].tianshu;}else{kaoqin=0;}yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie+kaoqin;yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie+kaoqin;yanglaobaoxian=(zhiwugongzi+zhiwubutie)*0.1;zhufang=yingfagongzi*0.05;shifagongzi=yingfagongzi-yanglaobaoxian-zhufang;emp_gongzi[i].zhiwugongzi=zhiwugongzi;emp_gongzi[i].zhiwubutie=zhufangbutie;emp_gongzi[i].zhufangbutie=zhufangbutie;emp_gongzi[i].kaoqin=kaoqin;emp_gongzi[i].yingfagongzi=yingfagongzi;emp_gongzi[i].yanglaobaoxian=yanglaobaoxian;emp_gongzi[i].zhufang=zhufang;emp_gongzi[i].shifagongzi=shifagongzi;}if (strcmp(emp[i].degree,gaojigongchengshi) == 0){zhiwugongzi=1350*(1+(emp[i].nianxian*5)/100);zhiwubutie=zhiwugongzi*25/100;zhufangbutie=(zhiwugongzi+zhiwubutie)*25/100;if (emp_kaoqin[i].tianshu>=20){kaoqin=10*emp_kaoqin[i].tianshu;}else if ((emp_kaoqin[i].tianshu>=10)&&(emp_kaoqin[i].tianshu<20)) {kaoqin=5*emp_kaoqin[i].tianshu;}else{kaoqin=0;}yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie+kaoqin;yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie+kaoqin;yanglaobaoxian=(zhiwugongzi+zhiwubutie)*0.1;zhufang=yingfagongzi*0.05;shifagongzi=yingfagongzi-yanglaobaoxian-zhufang;emp_gongzi[i].zhiwugongzi=zhiwugongzi;emp_gongzi[i].zhiwubutie=zhufangbutie;emp_gongzi[i].zhufangbutie=zhufangbutie;emp_gongzi[i].kaoqin=kaoqin;emp_gongzi[i].yingfagongzi=yingfagongzi;emp_gongzi[i].yanglaobaoxian=yanglaobaoxian;emp_gongzi[i].zhufang=zhufang;emp_gongzi[i].shifagongzi=shifagongzi;}printf("\n");}fwrite(emp_gongzi, sizeof(struct emp_gong),number, fp3);fclose(fp);fclose(fp2);fclose(fp3);if ((fp = fopen(nian, "rb+")) == NULL){printf("Can't open file\n");exit(0);}printf(" 更新成功!!\n");for (i = 0; fread(&emp_gongzi[i],sizeof(struct emp_gong),1,fp) == 1 ; i++){printf("编号%s 姓名%s 职务工资%f 职务补贴%f 住房补贴%f\n考勤管理奖%f 应发工资%f 养老保险%f 住房公积金%f 实发工资%f\n",emp_gongzi[i].num,emp_gongzi[i].name,emp_gongzi[i].zhiwugongzi,emp_gongzi[i].zhiwubutie,emp_gongzi[i].zhufangbutie,emp_gongzi[i].kaoqin,emp_gongzi[i].yingfagongzi,emp_gongzi[i].yanglaobaoxian, emp_gongzi[i].zhufang,emp_gongzi[i].shifagongzi);printf("\n\n\n");}fclose(fp);}void findnum(){FILE *fp;int i;char num[5];int flag=1;if ((fp = fopen("number.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}fread(&number,sizeof(int),1,fp);fclose(fp);if ((fp = fopen("emp_gong.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}fread(emp_gongzi,sizeof(struct emp_gong),number,fp);fclose(fp);printf("请您输入编号:\n");scanf("%s",num);for (i=0;i<number;i++){if (strcmp(num, emp_gongzi[i].num) == 0){printf("搜索成功!!\n");printf("编号%s 姓名%s 职务工资%f 职务补贴%f 住房补贴%f\n考勤管理奖%f 应发工资%f 养老保险%f 住房公积金%f 实发工资%f\n",emp_gongzi[i].num,emp_gongzi[i].name,emp_gongzi[i].zhiwugongzi,emp_gongzi[i].zhiwubutie,emp_gongzi[i].zhufangbutie,emp_gongzi[i].kaoqin,emp_gongzi[i].yingfagongzi,emp_gongzi[i].yanglaobaoxian,emp_gongzi[i].zhufang,emp_gongzi[i].shifagongzi);flag=2;}}if (flag==1){printf("该信息不存在\n");}}void findname(){FILE *fp;int i;char name[10];int flag=1;if ((fp = fopen("number.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}fread(&number,sizeof(int),1,fp);fclose(fp);if ((fp = fopen("emp_gong.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}fread(emp_gongzi,sizeof(struct emp_gong),number,fp);fclose(fp);printf("请您输入姓名:\n");scanf("%s",name);for (i=0;i<number;i++){if (strcmp(name, emp_gongzi[i].name) == 0){printf("搜索成功!!\n");printf("搜索成功!!\n");printf("编号%s 姓名%s 职务工资%f 职务补贴%f 住房补贴%f\n考勤管理奖%f 应发工资%f 养老保险%f 住房公积金%f 实发工资%f\n",emp_gongzi[i].num,emp_gongzi[i].name,emp_gongzi[i].zhiwugongzi,emp_gongzi[i].zhiwubutie,emp_gongzi[i].zhufangbutie,emp_gongzi[i].kaoqin,emp_gongzi[i].yingfagongzi,emp_gongzi[i].yanglaobaoxian, emp_gongzi[i].zhufang,emp_gongzi[i].shifagongzi);flag=2;}}if (flag==1){printf("该信息不存在\n");}}void findname2(){FILE *fp;int i;char name[10];int flag=1;if ((fp = fopen("number.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}fread(&number,sizeof(int),1,fp);fclose(fp);if ((fp = fopen("emp_gong.dat", "rb+")) == NULL){printf("Can't open file\n");exit(0);}fread(emp_gongzi,sizeof(struct emp_gong),number,fp);fclose(fp);printf("请您输入姓:\n");scanf("%s",name);for (i=0;i<number;i++){if (name[0]==emp_gongzi[i].name[0]){。
c语言职工工资管理系统代码
C语言职工工资管理系统代码简介职工工资管理是一项重要的任务,它涉及到工资计算、薪资发放、绩效评估等方面。
为了提高管理的有效性和准确性,许多公司和组织都开发了各种各样的工资管理系统。
本文将介绍一种基于C语言开发的职工工资管理系统代码。
代码功能及特点1. 基本功能•添加新员工信息•更新员工信息•计算员工工资•发放工资•查询员工信息•统计工资情况2. 特点•简单易懂:代码使用C语言编写,阅读和理解都相对简单。
•高效可靠:代码采用模块化设计,结构清晰,运行效率高,容错性强。
•跨平台支持:C语言是一种具有广泛应用的语言,可以在多个操作系统上运行。
代码实现1. 员工信息结构体定义struct Employee {int id; // 员工编号char name[20]; // 员工姓名float basicSalary; // 员工基本工资float performanceBonus; // 绩效奖金float salary; // 员工工资};2. 添加新员工信息函数void addEmployee(struct Employee *employee, int num) {printf("请输入员工编号:");scanf("%d", &(employee[num].id));// 输入其他员工信息...}3. 更新员工信息函数void updateEmployee(struct Employee *employee, int id) {int i;for (i = 0; i < num; i++) {if (employee[i].id == id) {// 更新员工信息...}}}4. 计算员工工资函数void calculateSalary(struct Employee *employee, int num) {int i;for (i = 0; i < num; i++) {employee[i].salary = employee[i].basicSalary + employee[i].performance Bonus;}}5. 发放工资函数void paySalary(struct Employee *employee, int num) {int i;for (i = 0; i < num; i++) {printf("员工编号:%d,工资:%.2f\n", employee[i].id, employee[i].salar y);}}6. 查询员工信息函数void searchEmployee(struct Employee *employee, int id) {int i;for (i = 0; i < num; i++) {if (employee[i].id == id) {// 输出员工信息...}}}7. 统计工资情况函数void statisticsSalary(struct Employee *employee, int num) { float totalSalary = 0;int i;for (i = 0; i < num; i++) {totalSalary += employee[i].salary;}printf("总工资:%f\n", totalSalary);}使用示例1. 添加员工信息struct Employee employees[100];int num = 0;addEmployee(employees, num);num++;2. 更新员工信息int id = 12345;updateEmployee(employees, id);3. 计算员工工资calculateSalary(employees, num);4. 发放工资paySalary(employees, num);5. 查询员工信息int id = 12345;searchEmployee(employees, id);6. 统计工资情况statisticsSalary(employees, num);总结本文介绍了一个基于C语言的职工工资管理系统代码。
C++员工工资管理系统源代码
#include <iomanip>#include <iostream>#include <fstream>#include <malloc.h>#include <stdlib.h>#include <string.h>using namespace std;#define NULL 0#define LEN sizeof(struct student)int const N=20;void Menu();void Pass();int n=0; //定义一个全局变量统计职工人数//——--------->定义一个职工信息的结构体struct student{char name[N]; //用来存放姓名char sex[N]; //用来存放性别long id; //用来存放编号float paid[3]; //用来存放工资int total; //用来存放总工资struct student *next;};//-------------->职工类class Information{public:Information() ; //构造函数.~Information() ; //析构函数.student *creat(); //建立链表void output(student *head); //显示职工信息int count(student *head); //定义函数count()统计职工总数student *insert(student*head); //指针函数*insert()用来添加职工信息.student *cancel(student *head,long id); //指针函数*cancel()用来删除职工信息. student *find(student *head,long id); //指针函数*find()用来查找职工信息.student *modify(student *head,long id); //指针函数*modife()用来修改职工的信息.void paixu(student *head); //定义paixu()函数将职工的总额从大到小排列并输出void average(student *head); //定义职工工资平均值的函数void save(student *head); //保存文件信息student *Read(); //读取文件信息private:student *p1,*p2,*p3,*head,st;};Information::Information(){cout<<" ******************************************************************************\n";cout<<" ------------------------<<欢迎您使用员工工资管理系统>>------------------------\n";cout<<" ******************************************************************************\n\n";}Information::~Information(){ cout<<" ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n";cout<<" \n"; cout<<" 本系统管理员\n"; cout<<" \n"; cout<<" \n"; cout<<" ------------------------<<谢谢您使用员工工资管理系统>>------------------------\n";cout<<" \n"; cout<<" \n"; cout<<" 欢迎下次使用\n"; cout<<" \n"; cout<<" \n"; cout<<" 再见\n"; cout<<" \n"; cout<<" ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n";}//------------>建立链表信息student *Information::creat(void){//定义一个指向struct student的结构体指针函数*creat()用来录入职工信息.char ch[N];n=0; //用来存放职工姓名p1=p2=(student *)malloc(LEN);//调用malloc()函数用来开辟一个新的存储单元cout<<" -------------<<请建立员工信息表,在姓名处键以# 结束输入!>>--------------"<<endl;cout<<" 姓名:";cin>>ch;head=NULL; //给指针head赋初值while (strcmp(ch,"#")!=0){ //调用字符比较函数strcmp()用来判断是否继续输入p1=(student *)malloc(LEN); //调用malloc()函数用来开辟一个新的存储单元strcpy(p1->name,ch); //将循环结构前面输入的姓名复制到结构体名为p1的数组name中cout<<" 性别:";cin>>p1->sex;cout<<" 编号:";cin>>p1->id;while((p1->id)<0||(p1->id)>100000) //判断输入的编号是否有效(100000个){cout<<" 对不起您的输入错误!请重新输入(>0<1000000): ";cin>>p1->id;}cout<<" 基本工资:";cin>>p1->paid[0];while((p1->paid[0])<0||(p1->paid[0])>100000) //判断输入的分数是否有效(>=0 <=100000){cout<<" 对不起您的输入错误!请重新输入(>0<100000): ";cin>>p1->paid[0];}cout<<" 加班工资:";cin>>p1->paid[1];while((p1->paid[1])<0||(p1->paid[1])>100000) //判断输入的分数是否有效(>=0<=100000){cout<<" 对不起您的输入错误!请重新输入(>0<100000): ";cin>>p1->paid[1];}cout<<" 其他奖金:";cin>>p1->paid[2];while((p1->paid[2])<0||(p1->paid[2])>100000) //判断输入的分数是否有效(>=0 <=100000){cout<<" 对不起您的输入错误!请重新输入(>0<100000): ";cin>>p1->paid[2];}p1->total=p1->paid[0]+p1->paid[1]+p1->paid[2]; //计算总额if(n==0)head=p1; //如果是输入第一组职工信息就将指针p1赋给指针headelse p2->next=p1; //否则将p1赋给p2所指结构体的next指针p2=p1; //将指针p1赋给指针p2n++; //将职工人数n的值加1cout<<"\n 姓名:";cin>>ch; //将输入的姓名存放到字符数组ch中}p2->next=NULL; //将p2所指结构体的next指针重新赋空值return (head);//将输入的第一组职工信息返回}//--------------->定义output()函数将职工的信息从头指针所指内容开始输出void Information::output(student *head)system("cls");if(head==NULL) cout<<" 这是一个空表,请先输入员工信息!\n";else{cout<<"-------------------------------------------------------------------------------\n";cout<<" *职工工资信息表*\n";cout<<"-------------------------------------------------------------------------------\n";cout<<"|编号| |姓名| |性别| |基本工资| |加班工资| |其他奖金| |总额|\n"; cout<<"-------------------------------------------------------------------------------\n";p1=head; //将头指针赋给pdo{cout<<setw(6)<<p1->id<<setw(10)<<p1->name<<setw(10)<<p1->sex<<setw(10)<<p1->paid[0]<<setw(10)<<p1->paid[1]<<setw(12)<<p1->paid[2]<<setw(12)<<p1->total<<endl;cout<<"-------------------------------------------------------------------------------\n";p1=p1->next; //将下一组职工信息的next指针赋给p}while(p1!=NULL); //若指针p非空则继续,目的是把所有的职工信息都传给指针p然后输出.}//------------>统计职工人数的函数int Information::count(struct student *head) //定义函数count()统计职工总数{if(head==NULL)return(0); //若指针head为空返回值为0else return(1+count(head->next)); //函数的递归调用}//----------->添加职工的成绩的函数student *Information::insert( student *head)//插入新结点定义一个指向struct student的结构体指针函数*insert()用来添加职工信息. {system("cls");cout<<"\t----------------<<请输入新增员工信息>>----------------\n"<<endl;p1=(student *)malloc(LEN); //使p1指向插入的新结点cout<<" 编号:";cin>>p1->id;while((p1->id)<0||(p1->id)>100000){cout<<" 对不起您的输入错误!请重新输入(>0<100000): ";cin>>p1->id; //将输入的编号存放到p1所指结构体的数组id中}cout<<" 姓名:";cin>>p1->name; //将输入的姓名存放到结构体名为p1的数组name中cout<<" 性别:";cin>>p1->sex;cout<<" 基本工资:";cin>>p1->paid[0];while((p1->paid[0])<0||(p1->paid[0])>100000){cout<<" 对不起您的输入错误!请重新输入(>0<100000): ";cin>>p1->paid[0]; //将输入的基本工资存放到p1所指结构体的数组paid中}cout<<" 加班工资:";cin>>p1->paid[1];while((p1->paid[1])<0||(p1->paid[1])>100000){cout<<" 对不起您的输入错误!请重新输入(>0<100000): ";cin>>p1->paid[1]; //将输入的加班工资存放到p1所指结构体的数组paid中}cout<<" 其他奖金:";cin>>p1->paid[2];while((p1->paid[2])<0||(p1->paid[2])>100000){cout<<" 对不起您的输入错误!请重新输入(>0<100000): ";cin>>p1->paid[2]; //将输入的其他奖金存放到p1所指结构体的数组paid中}p1->total=p1->paid[0]+p1->paid[1]+p1->paid[2];//计算总分p2=head; //将头指针赋给p2if(head==NULL) //若没调用次函数以前的头指针head为空{head=p1;p1->next=NULL;} //则将p1赋给头指针head并将p1所指结构体成员指针next赋空值else{while((p1->id>p2->id)&&(p2->next!=NULL)){p3=p2; //p3指向原p2指向的结点p2=p2->next;} //p2后移一个结点if(p1->id<=p2->id){if(head==p2){p1->next=head;head=p1;} //插入到第一个结点之前else{p3->next=p1;p1->next=p2;} //插入到p3所指结点之后}else{p2->next=p1;p1->next=NULL;} //插入到尾结点之后}n++; //将职工人数加1cout<<"\t----------------<<你输入的员工信息已经成功插入>>----------------"<<endl; return (head);}//------------>删除职工信息student *Information::cancel(student *head,long id) //定义一个指向struct student的结构体指针函数*delete()用来删除考生信息.{system("cls");if(head==NULL) //若调用次函数以前的头指针head为空{return(head);}else{p1=head; //否则将头指针赋给p1while(id!=p1->id&&p1->next!=NULL) //寻找要删除的结点当p1所指的职工编号不是输入的职工编号并且p1所指的next指针不为空{p2=p1;p1=p1->next;} //p2指向原p1指向的结点p1后移一个结点if(id==p1->id) //如果输入的职工编号是p1所指的职工编号//结点找到后删除{if(p1==head) head=p1->next; //如果head指针和p1指针相等则将下一个结点赋给指针head elsep2->next=p1->next; //否则将p1所指结点赋给p2所指结点将要删除的职工信息跳过去cout<<" 删除编号为"<<id<<"的职工\n";n--; //将职工人数减1}return(head); //将头指针返回}}/**************************修改职工数据**************************/student *Information::modify(student *head,long id){system("cls");cout<<"\t----------------<<请输入须修改的员工工资信息>>----------------\n"<<endl;p1=(student *)malloc(LEN); //使p1指向输入的结点p1=head; //否则将头指针赋给p1while(id!=p1->id&&p1->next!=NULL)//寻找结点当p1所指的职工编号不是输入的职工编号并且p1所指的next指针不为空{p1=p1->next; //p2指向原p1指向的结点p1后移一个结点}if(id==p1->id) //如果要查找的职工编号是p1所指的职工编号{cout<<"你需要修改的员工信息如下:\n";cout<<"------------------------------------------------------------------------------\n";cout<<"|编号| |姓名| |性别| |基本工资| |加班工资| |其他奖金| |总额|\n";cout<<"------------------------------------------------------------------------------\n";cout<<setw(6)<<p1->id<<setw(10)<<p1->name<<setw(10)<<p1->sex<<setw(10)<<p1->paid[0]<<setw(10)<<p1->paid[1]<<setw(12)<<p1->paid[2]<<setw(12)<<p1->total<<endl;cout<<"------------------------------------------------------------------------------\n";cout<<" 编号:";cin>>p1->id;while((p1->id)<0||(p1->id)>100000){cout<<" 对不起您的输入错误!请重新输入(>0<100000): ";cin>>p1->id; //将输入的编号存放到p1所指结构体的数组id中}cout<<" 姓名:";cin>>p1->name; //将输入的姓名存放到结构体名为p1的数组name中cout<<" 性别:";cin>>p1->sex;cout<<" 基本工资:";cin>>p1->paid[0];while((p1->paid[0])<0||(p1->paid[0])>100000){cout<<" 对不起您的输入错误!请重新输入(>0<100000): ";cin>>p1->paid[0]; //将输入的基本工资存放到p1所指结构体的数组paid中}cout<<" 加班工资:";cin>>p1->paid[1];while((p1->paid[1])<0||(p1->paid[1])>100000){cout<<" 对不起您的输入错误!请重新输入(>0<100000): ";cin>>p1->paid[1]; //将输入的加班工资存放到p1所指结构体的数组paid中}cout<<" 其他奖金:";cin>>p1->paid[2];while((p1->paid[2])<0||(p1->paid[2])>100000){cout<<" 对不起您的输入错误!请重新输入(>0<100000): ";cin>>p1->paid[2]; //将输入的其他奖金存放到p1所指结构体的数组paid中}p1->total=p1->paid[0]+p1->paid[1]+p1->paid[2]; //计算总分}elsecout<<" 需要修改的信息中没有编号为"<<id<<"的员工.\n\n"; //没有想要修改的结点信息getchar();return(head);}//------------>查找职工信息student *Information::find(student *head,long id)//定义一个指向struct student的结构体指针函数*find()用来查找职工信息.{system("cls");if(head==NULL) //若调用次函数以前的头指针head为空{cout<<" 这是一个空表,请先输入员工信息!\n";return(head);}else{p1=head; //否则将头指针赋给p1while(id!=p1->id&&p1->next!=NULL)//寻找结点当p1所指的职工编号不是输入的职工编号并且p1所指的next指针不为空{p1=p1->next; //p2指向原p1指向的结点p1后移一个结点}if(id==p1->id) //如果要查找的职工编号是p1所指的职工编号{cout<<"------------------------------------------------------------------------------\n";cout<<"|编号| |姓名| |性别| |基本工资| |加班工资| |其他奖金| |总额|\n"; cout<<"------------------------------------------------------------------------------\n";cout<<setw(6)<<p1->id<<setw(10)<<p1->name<<setw(10)<<p1->sex<<setw(10)<<p1->paid[0]<<setw(10)<<p1->paid[1]<<setw(12)<<p1->paid[2]<<setw(12)<<p1->total<<endl;cout<<"------------------------------------------------------------------------------\n";}elsecout<<"信息中没有编号为"<<id<<"的员工.\n"; //结点没找到return(head);}}//------------定义paixu()函数将职工的工资总额从大到小排列并输出void Information::paixu(student *head){system("cls");int i,k,m=0,j;student *p[N];//定义一个指向struct student的结构体指针数组pif(head!=NULL)//如果头指针是空则继续{ m=count(head);cout<<"------------------------------------------------------------------------------\n";cout<<" *员工工资统计表*\n";cout<<"------------------------------------------------------------------------------\n";cout<<"|编号| |姓名| |性别| |基本工资| |加班工资| |其他奖金| |总额| |名次|\n"; cout<<"------------------------------------------------------------------------------\n";p1=head;for(k=0;k<m;k++){p[k]=p1;p1=p1->next;}for(k=0;k<m-1;k++) //选择排序法for(j=k+1;j<m;j++)if(p[k]->total<p[j]->total){p2=p[k];p[k]=p[j];p[j]=p2;} //从大到小排列的指针for(i=0;i<m;i++){cout<<setw(6)<<p[i]->id<<setw(8)<<p[i]->name<<setw(9)<<p[i]->sex<<setw(10)<<p[i]->paid[0]<<setw(10)<<p[i]->paid[1]<<setw(10)<<p[i]->paid[2]<<setw(10)<<p[i]->total<<setw(10)<<i+1<<endl;cout<<"------------------------------------------------------------------------------\n";}}}//------------>求各工资的平均值的函数void Information::average(student *head){int k,m;float arg1=0,arg2=0,arg3=0;if(head==NULL)//如果头指针是空则继续{cout<<" 这是一个空表,请先输入员工信息!\n";}else{m=count(head);p1=head;for(k=0;k<m;k++){arg1+=p1->paid[0];arg2+=p1->paid[1];arg3+=p1->paid[2];p1=p1->next;}arg1/=m;arg2/=m;arg3/=m;cout<<" *各项工资的平均值*\n";cout<<"------------------------------------------------------------------------------\n";cout<<"\t\t基本工资的平均值: "<<setw(4)<<arg1<<"\n"<<"\t\t加班工资的平均值: "<<setw(4)<<arg2<<"\n"<<"\t\t奖金的平均值: "<<setw(4)<<arg3<<"\n";cout<<"------------------------------------------------------------------------------\n";}}//------------------->保存函数.void Information::save(student *head){system("cls");ofstream out("data.txt",ios::out);out<<count(head)<<endl;while(head!=NULL){ out<<head->name<<"\t"<<head->id<<"\t"<<"\t"<<head->sex<<"\t"<<head->paid[0]<<"\t"<<head->paid[1]<<"\t"<<head->paid[2]<<"\t"<<head->total<<endl;head=head->next;}}//———————————>读取文件的信息student *Information::Read(){system("cls");int i=0;p1=p2=( student *)malloc(LEN);head=NULL;ifstream in("data.txt",ios::in);in>>i;if(i==0){cout<<" data 文件中的数据为空,请先输入数据!"<<endl; return 0;}else {cout<<"\n原文件已保存的信息如下:\n";cout<<" ………………………………………………………………………………………………" <<endl;cout<<"|姓名| |编号| |性别| |基本工资| |加班工资| |其他奖金| |总额|\n";cout<<" ………………………………………………………………………………………………" <<endl;for(;i>0;i--){p1=(student *)malloc(LEN);in>>>>st.id>>st.sex>>st.paid[0]>>st.paid[1]>>st.paid[2]>>st.total;strcpy(p1->name,);p1->id=st.id;strcpy(p1->sex,st.sex);p1->paid[0]=st.paid[0];p1->paid[1]=st.paid[1];p1->paid[2]=st.paid[2];p1->total=st.total;if(n==0)head=p1; //如果是输入第一组职工信息就将指针p1赋给指针headelse p2->next=p1; //否则将p1赋给p2所指结构体的next指针p2=p1; //将指针p1赋给指针p2n++; //将n的值加1//显示读入数据cout<<" "<<p1->name<<"\t"<<p1->id<<" \t"<< p1->sex <<" \t"<< p1->paid[0] <<" \t"<< p1->paid[1] <<" \t"<< p1->paid[2] <<" \t"<< p1->total<<endl;cout<<" ………………………………………………………………………………………………" <<endl;}cout<<" 数据已经成功读取完毕!\n\n"<<endl;p2->next=NULL;in.close();return (head);}}//-------------------->菜单void Menu(){Information person;student *head=NULL;int choice;long i;head=person.Read();do{cout<<"\t※※※※※※※※※※※※※※※※※※※※※※※※※"<<endl;cout<<"\t※"<<endl;cout<<"\t※_ _ _ 欢迎进入员工信息统计管理_ _ _ "<<endl;cout<<"\t※"<<endl;cout<<"\t※※※※※※※※※※※※※※※※※※※※※※※※※"<<endl;cout<<"\t "<<endl;cout<<"\t 相关操作选项"<<endl;cout<<"\t "<<endl;cout<<"\t※※※※※※※※※※※※※※※※※※※※※※※※※"<<endl;cout<<"\t※※"<<endl;cout<<"\t※※"<<endl;cout<<"\t※ 1. 员工数据输入※"<<endl;cout<<"\t※※"<<endl;cout<<"\t※ 2. 显示员工工资※"<<endl;cout<<"\t※※"<<endl;cout<<"\t※ 3. 排序统计工资※"<<endl;cout<<"\t※※"<<endl;cout<<"\t※ 4. 查找员工工资※"<<endl;cout<<"\t※※"<<endl;cout<<"\t※ 5. 增加员工工资※"<<endl;cout<<"\t※※"<<endl;cout<<"\t※ 6. 删除员工工资※"<<endl; cout<<"\t※※"<<endl;cout<<"\t※7. 修改员工信息※"<<endl; cout<<"\t※※"<<endl;cout<<"\t※8. 成功保存信息※"<<endl;cout<<"\t※※"<<endl;cout<<"\t※9. 安全退出系统※"<<endl; cout<<"\t※※"<<endl;cout<<"\t※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"<<endl; cout<<" 请输入您的选择(0--9):";cin>>choice;while(choice<0||choice>9){cout<<" 对不起您的输入错误!请输入您的选择(0--9): ";cin>>choice;}//head=person.Read();switch(choice){case 1:head=person.creat();break;case 2://head=person.Read();person.output(head);break;case 3://head=person.Read();person.paixu(head); person.average(head);cout<<" 参加工作的员工人数为:"<<person.count(head)<<"人\n\n";break;case 4://head=person.Read();cout<<" 请输入要查找的编号:";cin>>i;while(i<0||i>100000){cout<<" 对不起您的输入错误!请重新输入: ";cin>>i;}person.find(head,i);break;case 5://head=person.Read();head=person.insert(head);person.output(head);break;case 6://head=person.Read();cout<<" 请输入要删除的编号:";cin>>i;while(i<0||i>100000){cout<<" 对不起您的输入错误!请重新输入: ";cin>>i;}head=person.cancel(head,i);person.output(head);break;case 7://head=person.Read();cout<<" 请输入要修改的编号:";cin>>i;while(i<0||i>100000){cout<<" 对不起您的输入错误!请重新输入: ";cin>>i;}person.modify(head,i);break;case 8:cout<<"信息已经成功保存!"<<endl;person.save(head);break;case 9:system("cls");break;default :cout<<" 对不起您的输入有误!请重新输入:\n";break;}}while(choice!=9);}//----------------->管理员登陆void Pass(){char UserName[30];char Passward[20];int i=0;cout<<"****************************************************************************\n";cout<<"\n\t为保护员工信息,只有管理员才可以进行管理!\n";cout<<"\n\t管理员名和登陆密码都只有4次机会,如果超过将自动退出系统!\n\n";cout<<"****************************************************************************\n";cout<<"\n请输入管理员名:";cin>>UserName;while (strcmp(UserName,"1")!=0){if(i>=3)exit(0); //超过4次则登陆失败,退出系统i++;cout<<"\n管理员名无效!请重新输入:";cin>>UserName;}cout<<"\n请输入密码:";cin>>Passward;while(strcmp(Passward,"1")!=0){if(i>=3)exit(0); //超过4次则登陆失败,退出系统i++;cout<<"\n密码输入错误!请重新输入:"<<endl; cin>>Passward;}cout<<"\n\t\t欢迎管理员的到来!!!!!\n"<<endl;}//------------------------------>主函数.int main(void){//设置背景色和字体颜色system("PAUSE"); //系统暂停system("cls"); //系统清屏Pass();system("PAUSE");system("cls");Menu();return 0; }//。
工资管理系统源代码
#include <stdio.h>#include <string.h>#include <ctype.h>#include <stdlib.h>#include <windows.h>#define MONTH_NUM 5 /* 最多的月份*/struct worker{int number; /* 每个工人的工号*/char name[15]; /* 每个工人的姓名*/int salary[MONTH_NUM]; /* 每个工人M月的工资*/ int sum; /* 每个工人的总工资*/ float average; /* 每个工人的平均工资*/ struct worker *next; //下一个节点的地址};typedef struct worker STU;char Menu(void);int Ascending(int a, int b);int Descending(int a, int b);void IntSwap(int *pt1, int *pt2);void CharSwap(char *pt1, char *pt2);void FloatSwap(float *pt1, float *pt2);STU *AppendNode(STU *head, const int m);STU *DeleteNode(STU *head, int nodeNum);STU *ModifyNode(STU *head, int nodeNum, const int m); STU *SearchNode(STU *head, int nodeNum);STU *Appendsalary(STU *head, const int m);void Totalsalary(STU *head, const int m);void Printsalary(STU *head, const int m);STU *Deletesalary(STU *head, const int m);void Modifysalary(STU *head, const int m);void Sortsalary(STU *head, const int m, int (*compare)(int a, int b));void Searchsalary(STU *head, const int m);void DeleteMemory(STU *head);void numberSwap(STU *head);main(){char ch,b;int m,a;STU *head = NULL;printf("\n\n\n\n\n\n\n\n\n");printf("``╭╮╭╮╭╮\n");printf("``│││││└╮\n");printf("╭┴┴———————┴┴╮~└—╯\n");printf("││╭—————╮\n");printf("│││哈│\n");printf("│●●│╭╮│喽! │\n");printf("│○╰┬┬┬╯○│o╰╯╰—————╯\n");printf("│╰—╯│\n");printf("╰——┬o———o┬——╯\n");printf(" ╭╮╭╮\n");printf(" ╰┴————┴╯\n");Sleep(3000);system("cls");printf("\n\n\n\n\n\n\n\n\n\n\n ≈~☆输入要记录的月份个数(m<10)☆~~`≈: "); scanf("%d", &m);system("cls");while (1){ch = Menu();switch (ch){case'1':head = Appendsalary(head, m);Totalsalary(head, m);break;case'2':Modifysalary(head, m);Totalsalary(head, m);printf("\nAfter modified\n");Printsalary(head, m);Sleep(1000);break;case'3':head = Deletesalary(head, m);printf("\nAfter deleted\n");Printsalary(head, m);break;case'4':do{Searchsalary(head, m);printf("\(≧▽≦)/ 是否要继续查询?Y or N:");scanf(" %c",&b);}while(b=='y'||b=='Y');break;case'5':Printsalary(head, m);printf("\(≧▽≦)/ 是否要选择排列方式?Y or N:");scanf(" %c",&b);while(b=='y'||b=='Y'){printf("你想降序排列还是升序排列?(1降序2升序):");scanf(" %d",&a);if(a==1){Sortsalary(head, m, Descending);printf("\nsorted in descending order by sum\n");Printsalary(head, m);}else{Sortsalary(head, m, Ascending);printf("\nsorted in ascending order by sum\n");Printsalary(head, m);}printf("O(∩_∩)O 是否继续选择排列方式?Y or N:");scanf(" %c",&b);}break;case'0':system("cls");printf("┴┬┴┬/ ̄\_/ ̄\\n");printf("┬┴┬┴▏▏▔▔▔▔\\n");printf("┴┬┴/\/﹨\n");printf("┬┴∕/)╭—————╮\n"); printf("┴┬▏●▏│再│\n"); printf("┬┴▏▔█◤╭╮│见! │\n"); printf("┴◢██◣\__/o╰╯╰—————╯\n"); printf("┬█████◣/\n");printf("┴█████████████◣\n");printf("◢██████████████▆▄\n");printf("◢██████████████▆▄\n");printf("█◤◢██◣◥█████████◤\\n");printf("◥◢████████████◤\\n");printf("┴███████████◤﹨\n");printf("┬││█████◤▏\n");printf("┴││)\n");printf("┬∕∕/▔▔▔\∕\n");printf("*∕___/﹨∕\/\\n");printf("┬┴┬┴┬┴\\_ ﹨/﹨\n");printf("┴┬┴┬┴┬┴\___\﹨/▔\﹨\n");exit(0);DeleteMemory(head);printf("End of program!");break;default:printf("Input error!");break;}}}char Menu(void)//主菜单{char ch;system("cls");printf("\n\n\n\n ━━●●━━━━━━━━━━━管理工人的工资━━━━━━...........(╯3╰)\n");printf(" 1.添加记录\n");printf(" 2.更新记录\n");printf(" 3.删除记录\n");printf(" 4.查询记录\n");printf(" 5.统计分析记录\n");printf(" 0.退出\n");printf(" ━━━━━━━━━━☆━━━━━━━━━━━━━━━━━☆━━━━━━━━━━\n");printf("` `.~ ☆~~`≈~☆☆~~`≈~☆☆~~`≈~☆.` `.~\n");printf("\n请输入你的选择:");scanf(" %c", &ch); /*在%c前面加一个空格,将存于缓冲区中的回车符读入*/system("cls");return ch;}STU *Appendsalary(STU *head, const int m)//添加新记录{int i = 0;char c;do{head = AppendNode(head, m); /*向链表末尾添加一个节点*/printf("\n O(∩_∩)O 你想再添加一个新的记录吗(Y/N)?");scanf(" %c",&c); /*%c前面有一个空格*/i++;}while (c=='Y' || c=='y');printf("%d new nodes have been apended!\n", i);return head;}STU *Deletesalary(STU *head, const int m)//删除记录{int i = 0, nodeNum;char c;do{printf("\n ⊙﹏⊙请输入你想删除的记录编号:");scanf("%d", &nodeNum);head = DeleteNode(head, nodeNum); /*删除工号为nodeNum的工人信息*/ Printsalary(head, m); /*显示当前链表中的各节点信息*/printf("Do you want to delete a node(Y/N)?");scanf(" %c",&c); /*%c前面有一个空格*/i++;}while (c=='Y' || c=='y');printf("%d nodes have been deleted!\n", i);return head;}void Modifysalary(STU *head, const int m)//修改记录{int i = 0, nodeNum;char c;do{printf("\n~~~^_^~~~ 请输入你想修改的记录编号:");scanf("%d", &nodeNum);head = ModifyNode(head, nodeNum, m); /*修改工号为nodeNum的节点*/ printf("Do you want to modify a node(Y/N)?");scanf(" %c",&c); /*%c前面有一个空格*/ i++;}while (c=='Y' || c=='y');printf("%d nodes have been modified!\n", i);}void Totalsalary(STU *head, const int m){STU *p = head;int i;while (p != NULL) /*若不是表尾,则循环*/{p->sum = 0;for (i=0; i<m; i++){p->sum += p->salary[i];}p->average = (float)p->sum / m;p = p->next; /*让p指向下一个节点*/}}void Sortsalary(STU *head, const int m, int (*compare)(int a, int b)){STU *pt;int flag = 0, i;do{flag = 0 ;pt = head;/*若后一个节点的总工资比前一个节点的总工资高,则交换两个节点中的数据注意只交换节点数据,而节点顺序不变,即节点next指针内容不进行交换*/ while (pt->next != NULL){if ((*compare)(pt->next->sum, pt->sum)){IntSwap(&pt->number, &pt->next->number);CharSwap(pt->name, pt->next->name);for (i=0; i<m; i++){IntSwap(&pt->salary[i], &pt->next->salary[i]);}IntSwap(&pt->sum, &pt->next->sum);FloatSwap(&pt->average, &pt->next->average);flag = 1;}pt = pt->next;}}while(flag);}/*交换两个整型数*/void IntSwap(int *pt1, int *pt2){int temp;temp = *pt1;*pt1 = *pt2;*pt2 = temp;}/*交换两个实型数*/void FloatSwap(float *pt1, float *pt2){float temp;temp = *pt1;*pt1 = *pt2;*pt2 = temp;}/*交换两个字符串*/void CharSwap(char *pt1, char *pt2){char temp[15];strcpy(temp, pt1);strcpy(pt1, pt2);strcpy(pt2, temp);}/*决定数据是否按升序排序,a<b为真,则按升序排序*/ int Ascending(int a, int b){return a < b;}/* 决定数据是否按降序排序,a>b为真,则按降序排序*/ int Descending(int a, int b){return a > b;}void Searchsalary(STU *head, const int m)//查询记录{int number, i,j,k=0,x,t=0;char str[100] = {'\0'}, temp[3];STU *findNode;printf("\n 请输入你想查找的记录编号:");scanf("%d", &number);findNode = SearchNode(head, number);if (findNode == NULL){printf("Not found!\n");}else{strcat(str, "工号");for(j=0;j<=strlen(findNode->name);j++)strcat(str," ");strcat(str, "姓名");for (i=1; i<=m; i++){if(findNode->salary[i]/10) t++;for(x=0;x<2*t;x++)strcat(str," ");strcat(str, "工资");itoa(i,temp, 10);strcat(str, temp);}strcat(str," 已发工资总和");if(findNode->sum/10) k++;for(i=0;i<k;i++)strcat(str," ");strcat(str," 个人平均工资");printf("%s", str);printf("\nNo.%3d %-8s ", findNode->number, findNode->name); for (i=0; i<m; i++){printf("%-7d ", findNode->salary[i]);}printf("%9d %9.2f\n", findNode->sum, findNode->average);}}void Printsalary(STU *head, const int m){STU *p = head;char str[100] = {'\0'}, temp[3];int i, j = 1,k,x,n=0,t=0;strcat(str, "工号");for(k=0;k<=strlen(p->name);k++)strcat(str," ");strcat(str, "姓名");for (i=1; i<=m; i++){if(p->salary[i]/10) t++;for(x=0;x<2*t;x++)strcat(str," ");strcat(str, "工资");itoa(i,temp, 10);strcat(str, temp);}strcat(str," 已发工资总和");if(p->sum/10) n++;for(k=0;k<n;k++)strcat(str," ");strcat(str," 个人平均工资");printf("%s", str); /* 打印表头*/while (p != NULL) /*若不是表尾,则循环打印*/{printf("\nNo.%3d %-8s ", p->number, p->name);for (i=0; i<m; i++){printf("%-7d ", p->salary[i]);}printf("%9d %9.2f\n", p->sum, p->average);p = p->next; /*让p指向下一个节点*/j++;}printf("\n");}STU *AppendNode(STU *head, const int m){STU *p = NULL;STU *pr = head;int j;p = (STU *)malloc(sizeof(STU)); /*为新添加的节点申请内存*/if (p == NULL) /*若申请内存失败,则打印错误信息,退出程序*/ {printf("No enough memory to alloc");exit(0);}if (head == NULL) /*若原链表为空表,则将新建节点置为首节点*/ {head = p;}else /*若原链表为非空,则将新建节点添加到表尾*/{/*若未到表尾,则继续移动指针pr,直到pr指向表尾*/while (pr->next != NULL){pr = pr->next;}pr->next = p; /*将新建节点添加到链表的末尾*/}pr = p; /*让pr指向新建节点*/printf("Input node data......");printf("\nInput number:");scanf("%d", &p->number);printf("Input name:");scanf("%s", p->name);for (j=0; j<m; j++){printf("Input salary%d:", j+1);scanf("%d", p->salary+j);}pr->next = NULL; /*将新建节点置为表尾*/return head; /*返回添加节点后的链表的头节点指针*/ }STU *ModifyNode(STU *head, int nodeNum, const int m){int j;STU *newNode;newNode = SearchNode(head, nodeNum);if (newNode == NULL){printf("Not found!\n");}else{printf("Input the new node data:\n");printf("Input name:");scanf("%s", newNode->name);for (j=0; j<m; j++){printf("Input salary%d:", j+1);scanf("%d", newNode->salary+j);}}return head;}STU *DeleteNode(STU *head, int nodeNum){STU *p = head, *pr = head;if (head == NULL) /*链表为空,没有节点,无法删除节点*/{printf("No Linked Table!\n");return(head);}/*若没找到节点nodeNum且未到表尾,则继续找*/while (nodeNum != p->number && p->next != NULL){pr = p;p = p->next;}if (nodeNum == p->number) /*若找到节点nodeNum,则删除该节点*/{if (p == head) /*若待删节点为首节点,则让head指向第2个节点*/{head = p->next;}else /*若待删节点非首节点,则将前一节点指针指向当前节点的下一节点*/ {pr->next = p->next;}free(p); /*释放为已删除节点分配的内存*/}else /*没有找到待删除节点*/{printf("This Node has not been found!\n");}return head; /*返回删除节点后的链表的头节点指针*/}STU *SearchNode(STU *head, int nodeNum){STU *p = head;int j = 1;while (p != NULL) /*若不是表尾,则循环*/{if (p->number == nodeNum) return p;p = p->next; /*让p指向下一个节点*/j++;}return NULL;}void DeleteMemory(STU *head){STU *p = head, *pr = NULL;while (p != NULL) /*若不是表尾,则释放节点占用的内存*/ {pr = p; /*在pr中保存当前节点的指针*/p = p->next; /*让p指向下一个节点*/free(pr); /*释放pr指向的当前节点占用的内存*/}}。
职工工资管理系统设计与源代码
职工工资管理系统一、设计目标:按照软件工程的规范,以SQL Server或Access为后台数据库,以Delphi 或Visual C++为前端开发工具,设计并实现一个简化的工资管理系统。
二、需求描述该系统存储了某单位全体职工和工资信息。
职工的基本信息包括:职工编号、姓名、性别、出生年月、职称、最后学历、工资和婚否。
每一个职工的工资信息包括:月份、职工编号、职工姓名、基本工资、津贴、岗贴、补贴、房贴、交通补贴、应发数、房租、储蓄、会费、个人所得税、应扣数、实发数、其他收入。
个人所得税计算方法设为:应发数少于800元为0;800~1000元的部分为5%;1000~5000元的部分为10%;5000元以上的部分为20%。
系统功能如下:1.职工信息管理:a.增加职工信息。
增加新职工时输入新职工的基本信息;b.删除某职工的基本信息。
如,职工死亡或离职时;c.修改某职工(指定职工编号)的某些信息(如,加工资、获得新学位、晋升职称、结婚或离婚)。
2.工资管理:a.增加工资信息。
当增加新职工时,添加某职工的工资信息;b.职工离职或死亡时,删除某职工的工资信息;c.修改工资信息。
当月开始增加或减少某些项工资或扣款数变化时,修改某职工的部分工资信息;3.查询与统计:a.查询职工信息,如查询全体职工信息,或按职称、学历、出生年月、出生年月之前/ 之后、已婚/ 未婚等条件或多个条件的组合来查询相应的职工信息。
b.查询指定编号职工的工资信息;c.按时间段统计职工收入或单位的工资支出。
三、概要设计四、详细设计void CWorkerMgr6View::OnExit(){OnExit();}void CWorkerMgr6View::OnRecordFirst(){if(m_pSet->IsBOF()){m_pSet->SetFieldNull(NULL);}else{m_pSet->MoveFirst();UpdateData(FALSE);//更新对话框窗口}}void CWorkerMgr6View::OnRecordLast(){m_pSet->MoveLast();UpdateData(FALSE);//更新对话框窗口}void CWorkerMgr6View::OnRecordNext(){if(m_pSet->IsBOF()){m_pSet->SetFieldNull(NULL);}//判断是否溢出if(m_pSet->IsEOF()){AfxMessageBox("已经到达最后记录");}else{m_pSet->MoveNext();}UpdateData(FALSE);}void CWorkerMgr6View::OnRecordPre(){if(m_pSet->IsBOF()){AfxMessageBox("已经到达第一个记录");m_pSet->MoveFirst();}m_pSet->MovePrev();UpdateData(FALSE);}void CWorkerMgr6View::OnAddWorker(){HRESULT hr;try{hr =m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象if(SUCCEEDED(hr)){hr=m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=worker.mdb","","",adModeUnknown);//连接数据库//上面一句中连接字串中的Provider是针对ACCESS2000环境的,对于ACCESS97,需要改为:Provider=Microsoft.Jet.OLEDB.3.51;}}catch(_com_error e)///捕捉异常{CString errormessage;errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage()); AfxMessageBox(errormessage);///显示错误信息}CAddWorker dl;if(dl.DoModal()==IDOK){m_pSet->AddNew();m_pSet->m_name=dl.m_nm;m_pSet->m_id=dl.m_ids;m_pSet->m_sex=dl.m_sx;m_pSet->m_born=dl.m_bn;m_pSet->m_zhichen=dl.m_zhch;m_pSet->m_xueli=dl.m_xli;m_pSet->m_salary=dl.m_sala;m_pSet->m_marry=dl.m_marr;m_pSet->Update();m_pSet->MoveLast();UpdateData(false);}OnAddMoney();}void CWorkerMgr6View::OnDeleteWorker(){HRESULT hr;try{hr =m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象if(SUCCEEDED(hr)){hr=m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=worker.mdb","","",adModeUnknown);///连接数据库///上面一句中连接字串中的Provider是针对ACCESS2000环境的,对于ACCESS97,需要改为:Provider=Microsoft.Jet.OLEDB.3.51;}}catch(_com_error e)///捕捉异常{CString errormessage;errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage()); AfxMessageBox(errormessage);///显示错误信息}CDelWorker dl;if(dl.DoModal()==IDOK)UpdateData(true);try{long id=dl.m_idid;CString str;str.Format("DELETE from worker where ID=%d",id);_variant_t RecordsAffected;m_pConnection->Execute((_bstr_t)str,&RecordsAffected,adCmdText); AfxMessageBox("删除成功!");}catch(_com_error*e){AfxMessageBox(e->ErrorMessage());}m_pSet->MoveNext();if(m_pSet->IsEOF())m_pSet->MoveLast();UpdateData(FALSE);}}void CWorkerMgr6View::OnChangWorker(){HRESULT hr;try{hr =m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象if(SUCCEEDED(hr)){hr=m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=worker.mdb","","",adModeUnknown);///连接数据库///上面一句中连接字串中的Provider是针对ACCESS2000环境的,对于ACCESS97,需要改为:Provider=Microsoft.Jet.OLEDB.3.51;}}catch(_com_error e)///捕捉异常{CString errormessage;errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage()); AfxMessageBox(errormessage);///显示错误信息}CChangeWork dl2;if(dl2.DoModal()==IDOK){UpdateData(true);long id=dl2.m_wid;m_pSet->MoveFirst();while(m_pSet->m_id!=dl2.m_wid)m_pSet->MoveNext();CChangeOne dl1;dl1.m_name1=m_pSet->m_name;dl1.m_id1=m_pSet->m_id;dl1.m_sex1=m_pSet->m_sex;dl1.m_born1=m_pSet->m_born;dl1.m_zhichen1=m_pSet->m_zhichen;dl1.m_xueli=m_pSet->m_xueli;dl1.m_salary1=m_pSet->m_salary;dl1.m_marry1=m_pSet->m_marry;if(dl1.DoModal()==IDOK){m_pSet->Edit();m_pSet->m_name=dl1.m_name1;m_pSet->m_id=dl1.m_id1;m_pSet->m_sex=dl1.m_sex1;m_pSet->m_born=dl1.m_born1;m_pSet->m_zhichen=dl1.m_zhichen1;m_pSet->m_xueli=dl1.m_xueli;m_pSet->m_salary=dl1.m_salary1;m_pSet->m_marry=dl1.m_marry1;m_pSet->Update();// m_pSet->MoveNext();UpdateData(false);}}}void CWorkerMgr6View::OnMShowDetail() {CMShowDetail dl;long id=m_pSet->m_id;m_pSet->MoveFirst();while(m_pSet->m_id!=id)m_pSet->MoveNext();dl.m_month=m_pSet->m_month;dl.m_id=m_pSet->m_id;dl.m_name=m_pSet->m_name;dl.m_base=m_pSet->m_base;dl.m_jintie=m_pSet->m_jintie;dl.m_gangtie=m_pSet->m_gangtie;dl.m_butie=m_pSet->m_butie;dl.m_fangtie=m_pSet->m_fangtie;dl.m_jiaotong=m_pSet->m_jiaotong;dl.m_yingfa=dl.m_base+dl.m_jintie+dl.m_gangtie+dl.m_butie+dl.m_fangtie+ dl.m_jiaotong;dl.m_fangzu=m_pSet->m_fangzu;dl.m_chuxu=m_pSet->m_chuxu;dl.m_huifei=m_pSet->m_huifei;if(dl.m_yingfa<800){dl.m_gerentax=0;}else if(dl.m_yingfa>=800&&dl.m_yingfa<=1000){dl.m_gerentax=dl.m_yingfa*0.05f;}else if(dl.m_yingfa>1000&&dl.m_yingfa<=5000){dl.m_gerentax=dl.m_yingfa*0.1f;}else if(dl.m_yingfa>5000){dl.m_gerentax=dl.m_yingfa*0.2f;}dl.m_yingkou=dl.m_fangzu+dl.m_chuxu+dl.m_huifei+dl.m_gerentax;dl.m_shifa=dl.m_yingfa-dl.m_yingkou;dl.m_other=m_pSet->m_other;dl.DoModal();}void CWorkerMgr6View::OnAddMoney(){CAddMoney dl;dl.m_id=m_pSet->m_id;dl.m_name=m_pSet->m_name;if(dl.DoModal()==IDOK){m_pSet->Edit();m_pSet->m_base=dl.m_base;m_pSet->m_month=dl.m_month;m_pSet->m_jintie=dl.m_jintie;m_pSet->m_gangtie=dl.m_gangtie;m_pSet->m_butie=dl.m_butie;m_pSet->m_fangtie=dl.m_fangtie;m_pSet->m_jiaotong=dl.m_jiaotong;dl.m_yingfa=dl.m_base+dl.m_jintie+dl.m_gangtie+dl.m_butie+dl.m_fangtie+ dl.m_jiaotong;m_pSet->m_yingfa=dl.m_yingfa;m_pSet->m_fangzu=dl.m_fangzu;m_pSet->m_chuxu=dl.m_chuxu;m_pSet->m_huifei=dl.m_huifei;if(dl.m_yingfa<800){dl.m_gerentax=0;}else if(dl.m_yingfa>=800&&dl.m_yingfa<=1000){dl.m_gerentax=dl.m_yingfa*0.05f;}else if(dl.m_yingfa>1000&&dl.m_yingfa<=5000){dl.m_gerentax=dl.m_yingfa*0.1f;else if(dl.m_yingfa>5000){dl.m_gerentax=dl.m_yingfa*0.2f;}m_pSet->m_gerentax=dl.m_gerentax;dl.m_yingkou=dl.m_fangtie+dl.m_chuxu+dl.m_huifei+dl.m_gerentax;m_pSet->m_yingkou=dl.m_yingkou;dl.m_shifa=dl.m_yingfa-dl.m_yingkou;m_pSet->m_shifa=dl.m_shifa;m_pSet->m_other=dl.m_other;m_pSet->Update();//m_pSet->MoveLast();UpdateData(false);}}void CWorkerMgr6View::OnDeleteMoney(){HRESULT hr;try{hr =m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象if(SUCCEEDED(hr)){hr=m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=worker.mdb","","",adModeUnknown);///连接数据库///上面一句中连接字串中的Provider是针对ACCESS2000环境的,对于ACCESS97,需要改为:Provider=Microsoft.Jet.OLEDB.3.51;}}catch(_com_error e)///捕捉异常{CString errormessage;errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage()); AfxMessageBox(errormessage);///显示错误信息}CDeleteMoney dl;if(dl.DoModal()==IDOK)UpdateData(true);try{long id=dl.m_id;CString str;str.Format("DELETE from worker where ID=%d",id);_variant_t RecordsAffected;m_pConnection->Execute((_bstr_t)str,&RecordsAffected,adCmdText); AfxMessageBox("删除成功!");}catch(_com_error*e){AfxMessageBox(e->ErrorMessage());}m_pSet->MoveNext();if(m_pSet->IsEOF())m_pSet->MoveLast();UpdateData(FALSE);}}void CWorkerMgr6View::OnChangeMoney(){HRESULT hr;try{hr =m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象if(SUCCEEDED(hr)){hr=m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=worker.mdb","","",adModeUnknown);}}catch(_com_error e) //捕捉异常{CString errormessage;errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage()); AfxMessageBox(errormessage); //显示错误信息}CChangeWork dl2;if(dl2.DoModal()==IDOK){UpdateData(true);long id=dl2.m_wid;m_pSet->MoveFirst();while(m_pSet->m_id!=dl2.m_wid)m_pSet->MoveNext();CChangeMoney dl1;dl1.m_month=m_pSet->m_month;dl1.m_name=m_pSet->m_name;dl1.m_id=m_pSet->m_id;dl1.m_base=m_pSet->m_base;dl1.m_jintie=m_pSet->m_jintie;dl1.m_gangtie=m_pSet->m_gangtie;dl1.m_butie=m_pSet->m_butie;dl1.m_fangtie=m_pSet->m_fangtie;dl1.m_jiaotong=m_pSet->m_jiaotong;dl1.m_yingfa=dl1.m_base+dl1.m_jintie+dl1.m_gangtie+dl1.m_butie+dl1.m_fa ngtie+dl1.m_jiaotong;dl1.m_fangzu=m_pSet->m_fangzu;dl1.m_chuxu=m_pSet->m_chuxu;dl1.m_huifei=m_pSet->m_huifei;if(dl1.m_yingfa<800){dl1.m_gerentax=0;}else if(dl1.m_yingfa>=800&&dl1.m_yingfa<=1000){dl1.m_gerentax=dl1.m_yingfa*0.05f;}else if(dl1.m_yingfa>1000&&dl1.m_yingfa<=5000){dl1.m_gerentax=dl1.m_yingfa*0.1f;}else if(dl1.m_yingfa>5000){dl1.m_gerentax=dl1.m_yingfa*0.2f;}dl1.m_yingkou=dl1.m_gerentax+dl1.m_fangzu+dl1.m_chuxu+dl1.m_huifei;dl1.m_shifa=dl1.m_yingfa-dl1.m_yingkou;dl1.m_other=dl1.m_other;if(dl1.DoModal()==IDOK){m_pSet->Edit();m_pSet->m_name=dl1.m_name;m_pSet->m_id=dl1.m_id;m_pSet->m_month=dl1.m_month;m_pSet->m_base=dl1.m_base;m_pSet->m_jintie=dl1.m_jintie;m_pSet->m_gangtie=dl1.m_gangtie;m_pSet->m_butie=dl1.m_butie;m_pSet->m_fangtie=dl1.m_fangtie;m_pSet->m_jiaotong=dl1.m_jiaotong;m_pSet->m_yingfa=dl1.m_base+dl1.m_jintie+dl1.m_gangtie+dl1.m_butie+dl1. m_fangtie+dl1.m_jiaotong;m_pSet->m_fangzu=dl1.m_fangzu;m_pSet->m_chuxu=dl1.m_chuxu;m_pSet->m_huifei=dl1.m_huifei;if(m_pSet->m_yingfa<800){m_pSet->m_gerentax=0;}else if(m_pSet->m_yingfa>=800&&m_pSet->m_yingfa<=1000){m_pSet->m_gerentax=m_pSet->m_yingfa*0.05f;}else if(m_pSet->m_yingfa>1000&&m_pSet->m_yingfa<=5000){m_pSet->m_gerentax=m_pSet->m_yingfa*0.1f;}else if(m_pSet->m_yingfa>5000){m_pSet->m_gerentax=m_pSet->m_yingfa*0.2f;}m_pSet->m_yingkou=dl1.m_fangzu+dl1.m_chuxu+dl1.m_huifei+m_pSet->m_geren tax;m_pSet->m_shifa=m_pSet->m_yingfa-m_pSet->m_yingkou;m_pSet->m_other=dl1.m_other;m_pSet->Update();// m_pSet->MoveNext();UpdateData(false);}}}void CWorkerMgr6View::OnFindMoney(){HRESULT hr;try{hr =m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象if(SUCCEEDED(hr)){hr=m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=worker.mdb","","",adModeUnknown);}}catch(_com_error e) //捕捉异常{CString errormessage;errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage()); AfxMessageBox(errormessage); //显示错误信息}CFindNo dl2;if(dl2.DoModal()==IDOK){UpdateData(true);long id=dl2.m_id;m_pSet->MoveFirst();while(m_pSet->m_id!=dl2.m_id)m_pSet->MoveNext();CMShowDetail dl1;dl1.m_month=m_pSet->m_month;dl1.m_name=m_pSet->m_name;dl1.m_id=m_pSet->m_id;dl1.m_base=m_pSet->m_base;dl1.m_jintie=m_pSet->m_jintie;dl1.m_gangtie=m_pSet->m_gangtie;dl1.m_butie=m_pSet->m_butie;dl1.m_fangtie=m_pSet->m_fangtie;dl1.m_jiaotong=m_pSet->m_jiaotong;dl1.m_yingfa=dl1.m_base+dl1.m_jintie+dl1.m_gangtie+dl1.m_butie+dl1.m_fa ngtie+dl1.m_jiaotong;dl1.m_fangzu=m_pSet->m_fangzu;dl1.m_chuxu=m_pSet->m_chuxu;dl1.m_huifei=m_pSet->m_huifei;if(dl1.m_yingfa<800){dl1.m_gerentax=0;}else if(dl1.m_yingfa>=800&&dl1.m_yingfa<=1000){dl1.m_gerentax=dl1.m_yingfa*0.05f;}else if(dl1.m_yingfa>1000&&dl1.m_yingfa<=5000){dl1.m_gerentax=dl1.m_yingfa*0.1f;}else if(dl1.m_yingfa>5000){dl1.m_gerentax=dl1.m_yingfa*0.2f;}dl1.m_yingkou=dl1.m_gerentax+dl1.m_fangzu+dl1.m_chuxu+dl1.m_huifei;dl1.m_shifa=dl1.m_yingfa-dl1.m_yingkou;dl1.m_other=dl1.m_other;dl1.DoModal();}}void CWorkerMgr6View::OnStaticsMoney(){HRESULT hr;try{hr =m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象if(SUCCEEDED(hr)){hr=m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=worker.mdb","","",adModeUnknown);}}catch(_com_error e) //捕捉异常{CString errormessage;errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage()); AfxMessageBox(errormessage); //显示错误信息}m_pSet->MoveFirst();float sum=0;while(!m_pSet->IsEOF()){sum=sum+m_pSet->m_shifa;m_pSet->MoveNext();}CString string;string.Format("%f",sum);MessageBox(string,"统计当月支出",MB_OKCANCEL);}五、测试及结果分析(a)在此前端主界面下查看后台数据库中员工的基本信息。
C++_工资管理系统_源代码(总11页)
C++_工资管理系统_源代码(总11页)-CAL-FENGHAI.-(YICAI)-Company One1-CAL-本页仅作为文档封面,使用请直接删除#include <>#include <>#include <>#include <>#define TITLE "\n 月份工号姓名应发工资各种折扣实发工资\n" #define DATA " %2d %4ld %-10s % % %\n",p1->month,p1->num,p1->name,p1->should_pay,p1->rebate,p1->actual_paytypedef struct pay{long num;short month;char name[20];float gw,jn,zw,zl,jt,yj;float should_pay;float fz,gj,sd,others;float rebate;float actual_pay;struct pay *next;}PAY;FILE *fp;PAY *p1=NULL,*p2=NULL,*head=NULL;void menu();PAY *input();void output();void save(PAY *head);PAY *open();PAY *insert();void search();PAY *del();PAY *revise();/*主程序模块*/void main(void){short sel;do{menu();scanf("%d",&sel);switch(sel){case 1:head=input(); 建工资档案\n");printf("\t\t\t\t2.新增工资信息\n");printf("\t\t\t\t3.修改工资信息\n");printf("\t\t\t\t4.删除工资信息\n");printf("\t\t\t\t5.查找工资信息\n");printf("\t\t\t\t6.分类信息列表\n");printf("\t\t\t\t7.保存信息\n");printf("\t\t\t\t0.退出\n");printf("\n\n\n\n\n\n\n\n");}/*输入模块*/PAY *input(){short n=1;p1=(PAY*)malloc(sizeof(PAY));if(p1==NULL){printf("内存不足,无法创建链表!");getch();}printf("\n请输入第%d位职工的信息(以工号为0结束):\n",n);printf(" 工号:");scanf("%d",&p1->num);if(p1->num==0){printf("按任意键返回!");getch();free(p1);return 0;}getchar();printf(" 姓名:");gets(p1->name);printf(" 工资月份:");scanf("%d",&p1->month);printf(" 岗位工资,技能工资,职务津贴,职龄津贴,交通补贴,业绩津贴:\n");scanf("%f,%f,%f,%f,%f,%f",&p1->gw,&p1->jn,&p1->zw,&p1->zl,&p1->jt,&p1->yj); printf(" 房租扣款,公积金,水电费,其它扣款:\n");scanf("%f,%f,%f,%f",&p1->fz,&p1->gj,&p1->sd,&p1->others);p1->should_pay=p1->gw+p1->jn+p1->zw+p1->zl+p1->jt+p1->yj;p1->rebate=p1->fz+p1->gj+p1->sd+p1->others;p1->actual_pay=p1->should_pay-p1->rebate;while(p1!=NULL){if(n==1)head=p1;elsep2->next=p1;n++;p2=p1;p1=(PAY*)malloc(sizeof(PAY));if(p1==NULL){printf("内存不足,无法创建链表!");getch();}printf("请输入第%d位职工的信息(以工号为0结束):\n",n);printf(" 工号:");scanf("%d",&p1->num);getchar();if(p1->num==0){p1=NULL;break;}printf(" 姓名:");gets(p1->name);printf(" 工资月份:");scanf("%d",&p1->month);printf(" 岗位工资,技能工资,职务津贴,职龄津贴,交通补贴,业绩津贴:\n");scanf("%f,%f,%f,%f,%f,%f",&p1->gw,&p1->jn,&p1->zw,&p1->zl,&p1->jt,&p1->yj); printf(" 房租扣款,公积金,水电费,其它扣款:\n");scanf("%f,%f,%f,%f",&p1->fz,&p1->gj,&p1->sd,&p1->others);p1->should_pay=p1->gw+p1->jn+p1->zw+p1->zl+p1->jt+p1->yj;p1->rebate=p1->fz+p1->gj+p1->sd+p1->others;p1->actual_pay=p1->should_pay-p1->rebate;}p2->next=NULL;部清单\n");printf("\t\t2.按月输出\n");printf("\t\t3.按工资段输出\n");printf("\t\t0.返回\n");scanf("%d",&sel);}while(sel!=1&&sel!=2&&sel!=3&&sel!=0);head=open();if(head==NULL)return;elseswitch(sel){case 1:printf("\n\t\t\t ******全部清单******\n");printf(TITLE);p1=head;do{printf(DATA);p1=p1->next;}while(p1!=NULL);break;case 2:flag=0;printf("输入要查的月份:");scanf("%d",&month);printf("\n\t\t\t******第%d月工资清单******\n",month); printf(TITLE);p1=head;do{if(p1->month==month){printf(DATA);p1=p1->next;flag=1;}elsep1=p1->next;}while(p1!=NULL);if(flag==0)printf("没有该月清单\n");break;case 3:flag=0;printf("输入最低工资:");scanf("%f",&min);printf("输入最高工资:");scanf("%f",&max);printf("\n\t\t ******%到%工资的名单******\n",min,max); printf(TITLE);p1=head;do{if(p1->actual_pay>min&&p1->actual_pay<max){printf(DATA);p1=p1->next;flag=1;}elsep1=p1->next;}while(p1!=NULL);if(flag==0)printf("没有该工资段的职工\n");break;case 0:break;}}while(sel!=0);}/*保存文件*/void save(PAY *head){short write;fp=fopen("","w");if(fp==NULL){printf("创建文件失败!");getch();return;}p1=p2=head;while(p1!=NULL){write=fwrite(p1,sizeof(PAY),1,fp);if(!write){printf("无法写入文件!");getch();return;}p1=p1->next;}fclose(fp);printf("成功存盘!");getch();}/*打开文件*/PAY *open(){short n=1,read;fp=fopen("","r");if(fp==NULL){printf("无法打开档案文件!");getch();return NULL;}if((p1=p2=(PAY*)malloc(sizeof(PAY)))==NULL) {printf("内存不足!");getch();return NULL;}read=fread(p1,sizeof(PAY),1,fp);if(!read){printf("文件读取出错!1");getch();return NULL;}if(p1->next==NULL)head=p1;else{do{if(n==1)head=p1;elsep2->next=p1;n++;p2=p1;if((p1=(PAY*)malloc(sizeof(PAY)))==NULL){printf("内存不足!");getch();return NULL;}read=fread(p1,sizeof(PAY),1,fp);if(!read){printf("文件读取出错!2");getch();return NULL;}}while(p1->next!=NULL);p2->next=p1;}return head;fclose(fp);}/*插入模块*/PAY *insert(){PAY *p3=NULL;char sel;head=open();if(head==NULL)return NULL;elsedo{printf("请输入要插入的职工信息:\n"); p3=(PAY*)malloc(sizeof(PAY));if(p3==NULL){printf("内存不足,无法创建链表!"); getch();}printf(" 工号:");scanf("%d",&p3->num);getchar();printf(" 姓名:");gets(p3->name);printf(" 工资月份:");scanf("%d",&p3->month);printf(" 岗位工资,技能工资,职务津贴,职龄津贴,交通补贴,业绩津贴:\n");scanf("%f,%f,%f,%f,%f,%f",&p3->gw,&p3->jn,&p3->zw,&p3->zl,&p3->jt,&p3->yj); printf(" 房租扣款,公积金,水电费,其它扣款:\n");scanf("%f,%f,%f,%f",&p3->fz,&p3->gj,&p3->sd,&p3->others);p3->should_pay=p3->gw+p3->jn+p3->zw+p3->zl+p3->jt+p3->yj;p3->rebate=p3->fz+p3->gj+p3->sd+p3->others;p3->actual_pay=p3->should_pay-p3->rebate;p1=head;while(p1!=NULL){p2=p1;p1=p1->next;}p2->next=p3;p3->next=NULL;printf("成功插入,是否继续?是(Y)否(N)\n");sel=getch();}while(sel=='Y'||sel=='y');printf("\n任意键返回,并存盘……\n");getch();return head;}/*查找模块*/void search(){short sel;long num;char name[20],choose;head=open();if(head==NULL)return;elsedo{do{printf("\n选择查找方式:\n");printf("\t\t1.按工号查找\n");printf("\t\t2.按姓名查找\n");scanf("%d",&sel);getchar();}while(sel!=1&&sel!=2);switch(sel){case 1:printf("输入要查的工号:");scanf("%ld",&num);break;case 2:printf("输入要查的姓名:");gets(name);break;}p1=head;while((p1->next!=NULL)&&(p1->num!=num)&&(strcmp(p1->name,name)!=0)) 工号删除\n");printf("\t\t2.按姓名删除\n");scanf("%d",&sel);getchar();}while(sel!=1&&sel!=2);switch(sel){case 1:printf("输入要删除的工号:");scanf("%ld",&num);break;case 2:printf("输入要删除的姓名:");gets(name);break;}p1=head;if((p1->num==num)||strcmp(p1->name,name)==0){head=p1->next;printf("删除信息成功!");}else{while((p1->next!=NULL)&&(p1->num!=num)&&(strcmp(p1->name,name)!=0)) {p2=p1;p1=p1->next;}if((p1->num==num)||strcmp(p1->name,name)==0){p2->next=p1->next;free(p1);printf("\n删除信息成功!\n");}elseprintf("\n没有该信息!\n");}printf("是否继续?是(Y)否(N)\n"); choose=getch();}while(choose=='Y'||choose=='y');printf("任意键返回,并存盘……");getch();return head;}/*修改模块*/PAY *revise(){short sel;long num;char name[20],choose;head=open();if(head==NULL)return NULL;elsedo{do{printf("\n查找要修改的对象:\n");printf("\t\t1.按工号查找\n");printf("\t\t2.按姓名查找\n");scanf("%d",&sel);getchar();}while(sel!=1&&sel!=2);switch(sel){case 1:printf("输入要查的工号:");scanf("%ld",&num);break;case 2:printf("输入要查的姓名:");gets(name);break;}p1=head;while((p1->next!=NULL)&&(p1->num!=num)&&(strcmp(p1->name,name)!=0)) //用成p1!=NULL有问题?p1=p1->next;if((p1->num==num)||strcmp(p1->name,name)==0){printf("您要修改的原始信息如下:\n");printf(TITLE);printf(DATA);printf("\n将上述信息改为如下信息:\n");printf(" 工号:");scanf("%d",&p1->num);getchar();printf(" 姓名:");gets(p1->name);printf(" 工资月份:");scanf("%d",&p1->month);printf(" 岗位工资,技能工资,职务津贴,职龄津贴,交通补贴,业绩津贴:\n");scanf("%f,%f,%f,%f,%f,%f",&p1->gw,&p1->jn,&p1->zw,&p1->zl,&p1->jt,&p1->yj); printf(" 房租扣款,公积金,水电费,其它扣款:\n");scanf("%f,%f,%f,%f",&p1->fz,&p1->gj,&p1->sd,&p1->others);p1->should_pay=p1->gw+p1->jn+p1->zw+p1->zl+p1->jt+p1->yj;p1->rebate=p1->fz+p1->gj+p1->sd+p1->others;p1->actual_pay=p1->should_pay-p1->rebate;}elseprintf("你要修改的信息不存在!\n");printf("是否继续?是(Y)否(N)\n");choose=getch();}while(choose=='Y'||choose=='y');printf("任意键返回,并存盘……");getch();return head;}。
c语言职工工资管理系统代码
c语言职工工资管理系统代码
(实用版)
目录
1.引言
2.系统功能介绍
3.系统设计与实现
4.系统测试与验证
5.总结
正文
一、引言
随着社会的快速发展,职工工资管理系统已经成为企事业单位不可或缺的一部分。
本文将介绍一个基于 C 语言编写的职工工资管理系统代码,以满足企事业单位对职工工资管理的需求。
二、系统功能介绍
该职工工资管理系统主要包括以下功能:
1.员工信息管理:用于添加、修改和删除员工的基本信息,如姓名、工号、性别、出生日期、职位、电话等。
2.工资信息管理:用于录入、修改和删除员工的工资信息,包括基本工资、绩效工资、奖金、扣款等。
3.查询功能:提供按工号、姓名、职位等多种条件查询员工信息及工资信息。
4.打印功能:支持打印员工工资单。
三、系统设计与实现
本系统采用 C 语言编写,利用结构体和文件操作实现员工信息和工资信息的存储和管理。
系统主要包括以下几个模块:
1.数据结构设计:定义员工结构体和工资结构体,用于存储员工信息和工资信息。
2.文件操作:实现员工信息和工资信息的存储和读取,采用文件存储数据,确保数据安全性。
3.功能模块:实现员工信息管理、工资信息管理、查询和打印功能。
四、系统测试与验证
为确保系统的正确性和可靠性,对系统进行了详细测试。
测试结果表明,本系统能够正确处理各种操作,满足用户需求。
五、总结
本文介绍了一个基于 C 语言编写的职工工资管理系统代码。
该系统具有简单易用、功能齐全、安全性高等特点,可满足企事业单位对职工工资管理的需求。
C语言课程设计职工工资信息管理系统源代码
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <conio.h>#define N 10000int choice;struct employee{int num;int position;char name[10000];char sex[2];int salary;int i,max,t;}em[N];struct empsalary{char name[10000];int salary;}emps[N];void manage();void query();void input();void display();void change();void del();void add();void paixu();int changeposition();int changesalary();void querysalary();void creat();void main(){do{printf("欢迎进入职工管理系统中文版\n"); printf("请你选择操作类型:\n");printf("1进入管理系统\n");printf("2进入查询系统\n");printf("0退出系统\n");scanf("%d",&choice);switch(choice){case 1:manage();break;case 2:query();break;case 0:{printf("谢谢使用,再见\n");exit(0);}default:{printf("输入有错误请重新输入:\n");return;}}}while(1);}void manage(){int choicemanage;char choice='y';while(choice=='y'||choice=='Y'){printf("欢迎进入管理系统\n");printf("请你选择操作类型:\n");printf("1输入职工信息\n");printf("2显示职工信息\n");printf("3修改职工信息\n");printf("4追加一个职工信息\n");printf("5删除一个职工信息\n");printf("6排序\n");printf("0返回\n");scanf("%d",&choicemanage);switch(choicemanage){case 1:input();break;case 2:display();break;case 3:change();break;case 4:add();break;case 5:del();case 6:paixu();break;case 0:printf("谢谢你的使用再见\n");return;default:printf("你的输入有错请重新输入\n"); }printf("是否继续管理?(y/n)");scanf("%s",&choice);}if(toupper(choice)=='N'||(choice)=='n'){printf("输入完毕,任意键返回\n");getch();return;}}void input(){FILE *fp;int i=0;char choiceinput='y';if((fp=fopen("employee.txt","w"))==NULL) return;while(choiceinput=='y'||choiceinput=='Y'){i++;printf("第%d个职工\n",i);printf("\n");printf("请你输入工号:\n");scanf("%d",&em[i].num);printf("\n");printf("请你输入职位:\n");printf("1董事长2总经理3副总经理\n");printf("4经理5副经理6秘书\n");printf("7技术员8领班9员工\n");scanf("%d",&em[i].position);printf("\n");printf("请你输入姓名:\n");scanf("%s",em[i].name);printf("\n");printf("请你输入性别以m为男f为女:\n");scanf("%s",em[i].sex);printf("\n");printf("请你输入工资:\n");scanf("%d",&em[i].salary);printf("\n");printf("是否继续输入?(y/n)\n");scanf("%s",&choiceinput);fwrite(&em[i],sizeof(struct employee),1,fp);}if(toupper(choiceinput)=='N'){fclose(fp);printf("输入完毕,任意键返回\n");getch();return;}}void display(){FILE *fp;int i;if((fp=fopen("employee.txt","r"))==NULL)return;printf("输出结果:\n");for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++) {printf("工号%d\n",em[i].num);printf("职位为%d\n",em[i].position);printf("1董事长2总经理3副总经理\n");printf("4经理5副经理6秘书\n");printf("7技术员8领班9员工\n");printf("姓名为%s\n",em[i].name);printf("性别为%s\n",em[i].sex);printf("其中m为男f为女\n");printf("工资为%d\n",em[i].salary);}printf("完毕按任意键返回\n");getch();fclose(fp);return;}void change(){FILE *fp;int i;char chname[8];int choicechange;printf("请你输入要修改的人的姓名:\n");scanf("%s",&chname);if((fp=fopen("employee.txt","w+"))==NULL){printf("不能够打开这个文件\n");return;}for(i=0;i<N;i++){if(strcmp(chname,em[i].name)==0){printf("这是你要修改的人的信息\n");printf("工号为%d\n 职位为%d\n 姓名为%s\n 性别为%s\n 工资为%d\n",em[i].num,em[i].position,em[i].name,em[i].sex,em[i].salary);printf("请你输入要修改的部分:\n");printf("1修改职位\n");printf("2修改工资\n");printf("0退出系统\n");printf("请选择\n");scanf("%d",&choicechange);switch(choicechange){case 1:em[i].position=changeposition();break;case 2:em[i].salary=changesalary();break;case 0:return;default :printf("输入有错误");}fwrite(&em[i],sizeof(struct employee),1,fp); }}fclose(fp);printf("操作完成按任意键返回\n");getch();return;}int changeposition(){int newposition;printf("请你输入新职位:\n");printf("1董事长2总经理3副总经理\n"); printf("4经理5副经理6秘书\n"); printf("7技术员8领班9员工\n"); scanf("%d",&newposition);return(newposition);}int changesalary(){int newsalary;printf("请你输入新的工资:\n");scanf("%d",&newsalary);return(newsalary);}void add(){struct employee emp;FILE *fp;int i=0;if((fp=fopen("employee.txt","ab+"))==NULL){printf("不能够打开这个文件\n");getch();return;}printf("请你输入新人的内容:\n");printf("请你输入工号:\n");scanf("%d",&em[i].num);printf("请你输入职位:\n");printf("1董事长2总经理3副总经理\n");printf("4经理5副经理6秘书\n");printf("7技术员8领班9员工\n");scanf("%d",&emp.position);printf("请你输入姓名:\n");scanf("%s",);printf("请你输入性别以m为男f为女:\n");scanf("%s",emp.sex);printf("请你输入工资:\n");scanf("%d",&emp.salary);fwrite(&emp,sizeof(struct employee),1,fp);rewind(fp);printf("插入完毕,按任意键返回\n");getch();fclose(fp);return;}void del(){int i=0;char delname[8];FILE *fp;if((fp=fopen("employee.txt","w"))==NULL){printf("文件为空,不能够打开\n");printf("按任意键返回\n");getch();return;}printf("请你输入要删除的人的姓名:\n");scanf("%s",delname);for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++) {if(strcmp(em[i].name,delname)!=0)fwrite(&em[i],sizeof(struct employee),1,fp);}fclose(fp);if((fp=fopen("employee.txt","r"))==NULL)return;printf("新的职工的信息为:\n");for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++) {printf("工号%d",em[i].num);printf("职位为%d",em[i].position);printf("1董事长2总经理3副总经理\n");printf("4经理5副经理6秘书\n");printf("7技术员8领班9员工\n");printf("姓名为%s\n",em[i].name[8]);printf("性别为%s\n",em[i].sex[2]);printf("其中m为男f为女\n");printf("工资为%d\n",em[i].salary);fclose(fp);}}void query(){FILE *fp;int i=0;char quename[8];if((fp=fopen("employee.txt","r"))==NULL){printf("不能够打开文件,按任意键返回\n");getch();return;}printf("请你输入要查询的人的姓名\n");scanf("%s",quename);for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++) {if(strcmp(em[i].name,quename)==0){printf("\t\t\n查询到的职工号或姓名为的信息如下:\n");printf("以下是你要查询的人的信息\n");printf("工号%d",em[i].num);printf("职位为%d",em[i].position);printf("\t 1董事长2总经理3副总经理\n");printf("\t 4经理5副经理6秘书\n");printf("\t 7技术员8领班9员工\n");printf("姓名为%s\n",em[i].name);printf("性别为%s\n",em[i].sex);printf("\t其中m为男f为女\n");printf("工资为%d\n",em[i].salary);printf("\n");printf("查询完毕,按任意键返回\n");getch();fclose(fp);return;}}printf("没有这样的人,按任意键返回\n");getch();fclose(fp);return;}void querysalary(){int i;FILE *fp1,*fp2;creat();if((fp1=fopen("employee.txt","w+"))==NULL)return;for(i=0;fread(&em[i],sizeof(struct employee),1,fp1)!=0;i++) {printf("输出结果为:\n");printf("工号%d",em[i].num);printf("职位为%d",em[i].position);printf(" 1董事长2总经理3副总经理\n");printf(" 4经理5副经理6秘书\n");printf(" 7技术员8领班9员工\n");printf("姓名为%s\n",em[i].name[8]);printf("性别为%s\n",em[i].sex[2]);printf("其中m为男f为女\n");printf("工资为%d\n",em[i].salary);strcpy(emps[i].name,em[i].name);emps[i].salary=em[i].salary;}if((fp2=fopen("empsalary.txt","w"))==NULL)return;for(i=0;i<N;i++)fwrite(&emps[i],sizeof(struct empsalary),1,fp2);fclose(fp1);fclose(fp2);}void creat(){FILE *fp;if((fp=fopen("D:\\employee.txt","w+"))==NULL)return;input();fclose(fp);}void paixu(){int max,i,t,j;for(i=1;i<10;i++){max=em[i].salary;for(j=i;j<10;j++){if(em[j].salary>max){max=em[j].salary;t=em[j].salary;em[j].salary=t;}}}printf("姓名工资工号性别职位\n");for(i=1;i<10;i++)printf(" %s %d %d %s %d\n ",em[i].name,em[i].salary,em[i].num,em[i].sex,em[i].position);}。
c语言职工工资管理系统代码
C语言职工工资管理系统代码1. 项目简介本项目是一个用C语言编写的职工工资管理系统。
该系统旨在帮助企业或组织更好地管理职工的工资信息,包括薪资计算、数据存储和查询等功能。
通过该系统,可以提高工资管理的效率和准确性,减少人力资源部门的负担。
2. 功能需求本系统需要实现以下功能:•添加新员工:输入员工姓名、基本工资、津贴等信息,并生成唯一的员工ID。
•删除员工:根据员工ID删除指定员工信息。
•修改员工信息:根据员工ID修改指定员工的基本信息。
•计算薪资:根据员工ID计算指定员工的实际薪资,并将结果保存到数据库中。
•查询薪资:根据员工ID查询指定员工的薪资信息。
3. 数据结构设计为了存储职工的基本信息和薪资数据,我们可以使用以下数据结构:3.1 员工结构体定义struct Employee {int id; // 员工IDchar name[50]; // 员工姓名float basicSalary; // 基本工资float allowance; // 津贴float actualSalary; // 实际薪资};3.2 员工数组定义struct Employee employees[100]; // 最多存储100个员工的信息int employeeCount = 0; // 当前员工数量4. 系统实现4.1 添加新员工void addEmployee() {struct Employee employee;printf("请输入员工姓名:");scanf("%s", );printf("请输入基本工资:");scanf("%f", &employee.basicSalary);printf("请输入津贴:");scanf("%f", &employee.allowance);employee.id = employeeCount + 1;employee.actualSalary = employee.basicSalary + employee.allowance;employees[employeeCount] = employee;employeeCount++;printf("添加成功!员工ID为:%d\n", employee.id);}4.2 删除员工void deleteEmployee() {int id;printf("请输入要删除的员工ID:");scanf("%d", &id);int index = findEmployeeIndex(id);if (index == -1) {printf("未找到对应的员工信息。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include <iostream>#include <fstream>#include <string.h>#include <conio.h>using namespace std;//*************Staff类************1class Staff{public:char name[10]; //姓名char number[10];//卡号float SPWages;//应发工资float APWages;//实发工资float Allowance; //津贴float Gtie; //岗贴float Subsidy; //补贴float Tax;//税金Staff *Next;void Input(){// ofstream file("sort.txt");cout<<"\t\t请输入职工的姓名:";cin>>name;cout<<"\t\t请输入职工的卡号:";cin>>number;cout<<"\t\t请输入应发工资:";cin>>SPWages;while(SPWages<0){ cout<<"输入错误!请重新输入:"<<endl;cout<<"\t\t请输入应发工资:";cin>>SPWages;}cout<<"\t\t请输入津贴:";cin>>Allowance;while(Allowance<0){ cout<<"输入错误!请重新输入:"<<endl;cout<<"\t\t请输入津贴:";cin>>Allowance;}cout<<"\t\t请输入岗贴:";cin>>Gtie;while(Gtie<0){ cout<<"输入错误!请重新输入:"<<endl;cout<<"\t\t请输入补贴岗贴:";cin>>Gtie;}cout<<"\t\t请输入岗贴:";cin>>Subsidy;while(Subsidy<0){ cout<<"输入错误!请重新输入:"<<endl;cout<<"\t\t请输入补贴:";cin>>Subsidy;}// file.close();}void ReadFile(istream &in){in>>name>>number>>SPWages>>Allowance>>Gtie>>Subsidy;}void Show(){ if(SPWages<1100) Tax=0;if((SPWages>=1100.0)&&(SPWages<1600.0)) Tax=(SPWages-1100)*0.05;if((SPWages>1600)&&(SPWages<2600)) Tax=(SPWages-1600)*0.1+25;if((SPWages>=2600)&&(SPWages<=5600)) Tax=(SPWages-2600)*0.15+125;if(SPWages>5600) Tax=(SPWages-5600)*0.2+575;APWages=SPWages+Allowance+Gtie+Subsidy-Tax;// cout<<"姓名:"<<"\t"<<"卡号:"<<"\t"<<"应发工资:"<<"\t"<<"津贴:"<<"\t"<<"岗贴:"<<"\t"<<"补贴:"<<"\t"<<"税金:"<<"\t"<<"实发工资"<<endl;cout<<name<<"\t"<<number<<"\t"<<SPWages<<"\t\t"<<Allowance<<"\t"<<Gtie<<"\t"<<Subsid y<<"\t"<<Tax<<"\t"<<APWages<<endl;}};//**********Staffmassage类***********2class Staffmassage{public:Staffmassage();~Staffmassage();void ShowMenu();void Find();//查找void Save();//保存void ModifyItem();void RemoveItem();void Display(){ cout<<"姓名:"<<"\t"<<"卡号:"<<"\t"<<"应发工资:"<<"\t"<<"津贴:"<<"\t"<<"岗贴:"<<"\t"<<"补贴:"<<"\t"<<"税金:"<<"\t"<<"实发工资"<<endl;for(Staff *p=Head->Next;p!=End;p=p->Next)p->Show();cout<<"请继续……";getch();}void AddItem(){End->Input();End->Next=new Staff;End=End->Next;cout<<"添加成功!"<<endl;cout<<"请继续……";getch();}private:Staff *Head,*End;ifstream in;ofstream out;Staff *FindItem(char *name){ for(Staff *p=Head;p->Next!=End;p=p->Next)//匹配成功则返回上一指针,不成功则返回空if(!strcmp(p->Next->name,name))return p;return NULL;}Staff *Findnumber(char *number){ for(Staff *p=Head;p->Next!=End;p=p->Next)//匹配成功则返回上一指针,不成功则返回空if(!strcmp(p->Next->number,number))return p;return NULL;}};//************构造函数************3Staffmassage::Staffmassage(){ Head=new Staff;Head->Next=new Staff;End=Head->Next;in.open("sort.txt");cout<<"新系统!请先输入。
"<<endl;else{ while(!in.eof()){ End->ReadFile(in);if(End->name[0]=='\0')break;End->Next=new Staff;End=End->Next;}in.close();cout<<"\t\t读取职工工资信息成功!"<<endl;}}//*********析构函数********4Staffmassage::~Staffmassage(){ Save();for(Staff *temp;Head->Next!=End;){ temp=Head->Next;Head->Next=Head->Next->Next;delete temp;}delete Head,End;}//********菜单********5void Staffmassage::ShowMenu(){ cout<<" *欢迎进入职工工资管理系统"<<endl;cout<<"*************************************"<<endl;cout<<" *1.增加工资信息"<<endl;cout<<" *2.显示工资信息"<<endl;cout<<" *3.查找工资信息"<<endl;cout<<" *4.删除工资信息"<<endl;cout<<" *5.修改工资信息"<<endl;cout<<" *0.安全推出系统"<<endl;cout<<"\n\t\t\n\t\t请选择:";}//*********查找函数********6void Staffmassage::Find(){ char name[20],number[10];Staff *p=NULL;cout<<"\n\t\t*****************************\n";cout<<"\t\t*1.按职工的姓名查找\n\t\t*2.按职工的卡号查找";cout<<"\n\t\t请选择:";cin>>x;switch(x){ case 1:{ c out<<"\t\t请选择要查找职工的姓名:";cin>>name;if(p=FindItem(name)){ cout<<"姓名:"<<"\t"<<"卡号:"<<"\t"<<"应发工资:"<<"\t"<<"津贴:"<<"\t"<<"岗贴:"<<"\t"<<"补贴:"<<"\t"<<"税金:"<<"\t"<<"实发工资"<<endl;p->Next->Show();cout<<"请继续……";getch();}else{ cout<<"\t\t没有找到!"<<"\n"<<endl;cout<<"请继续……";getch();}}break;case 2:{cout<<"请输入要查找职工的卡号:";cin>>number;if(p=Findnumber(number)){ c out<<"姓名:"<<"\t"<<"卡号:"<<"\t"<<"应发工资:"<<"\t"<<"津贴:"<<"\t"<<"岗贴:"<<"\t"<<"补贴:"<<"\t"<<"税金:"<<"\t"<<"实发工资"<<endl;p->Next->Show();cout<<"请继续……";getch();}else{ c out<<"\t\t没有找到!"<<"\n"<<endl;cout<<"请继续……";getch();}}break;}}//*********修改信息*********7void Staffmassage::ModifyItem() // 修改信息{ char number[10];Staff *p=NULL;cout<<"请输入要修改职工的卡号:";cin>>number;if(p=Findnumber(number)){ cout<<"已找到职工的信息:"<<endl;p->Next->Show();cout<<"请输入新的信息:"<<endl;p->Next->Input();cout<<"修改成功!"<<endl;cout<<"请继续……";getch();}else{ cout<<"\t\t没有找到!"<<"\n"<<endl;cout<<"请继续……";getch();}}//*********删除信息**********8void Staffmassage::RemoveItem() //删除信息{ char number[10];Staff *p=NULL,*temp=NULL;cout<<"请输入要删除职工的姓名:"<<endl;cin>>number;if(p=Findnumber(number)){ temp=p->Next;p->Next=p->Next->Next;cout<<"姓名:"<<"\t"<<"卡号:"<<"\t"<<"应发工资:"<<"\t"<<"津贴:"<<"\t"<<"岗贴:"<<"\t"<<"补贴:"<<"\t"<<"税金:"<<"\t"<<"实发工资"<<endl;p->Next->Show();delete temp;cout<<"\t\t删除成功!"<<endl;//cin>>name;cout<<"请继续……";getch();}else{ cout<<"\t\t没有找到!"<<"\n"<<endl;cout<<"请继续……";getch();}}//*********保存函数*********10void Staffmassage::Save(){ out.open("sort.txt");for(Staff *p=Head->Next;p!=End;p=p->Next)cout<<p->name<<"\t"<<p->number<<"\t"<<p->SPWages<<"\t\t"<<p->Allowance<<"\t"<<p ->Gtie<<"\t"<<p->Subsidy<<"\t"<<p->Tax<<"\t"<<p->APWages<<"\n";in.close();}//*********主函数*********11int main(){ system("color 012");int x,i=0;bool quit=false;cout<<"\t\t * 欢迎进入职工工资管理系统* "<<endl;Staffmassage company;cout<<"按任意键开始……";getch();while(!quit){ system("cls");company.ShowMenu();cin>>x;switch(x){ case 0: cout<<"姓名:"<<"\t"<<"卡号:"<<"\t"<<"应发工资:"<<"\t"<<"津贴:"<<"\t"<<"岗贴:"<<"\t"<<"补贴:"<<"\t"<<"税金:"<<"\t"<<"实发工资"<<endl;quit=true;break;case 1: company.AddItem();break;case 2: company.Display();break;case 3: company.Find();break;case 4: company.RemoveItem();break;case 5: company.ModifyItem();break;}}return 0; }。