C-员工工资管理系统的源代码

合集下载

c语言课程设计职工工资管理系统源代码

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);}下面是实验结果。

员工工资管理系统源代码

员工工资管理系统源代码

#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,&st[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();elseif (x==6){printf(" ****** **** **** * * ***** * *\n");printf("* * * * * * * * * * *\n");printf("* * * * * * * * * * *\n");printf(" ****** ******** ******** ** * * * *\n");printf(" * * * ** * * * *\n");printf(" * * * ** * * * *\n");printf(" ****** **** **** ** ***** ***** \n");// printf("333333\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员工工资管理系统源代码

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(c h,”#")!=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 然后输出。

c语言职工工资管理系统代码

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语言的职工工资管理系统代码。

工资管理系统源代码

工资管理系统源代码

#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指向的当前节点占用的内存*/}}。

C工资管理系统源代码

C工资管理系统源代码
}
/*插入模块*/
PAY *insert()
{
PAY *p3=NULL;
char sel;
head=open();
if(head==NULL)
return NULL;
else
do
{
printf("请输入要插入的职工信息:\n");
p3=(PAY*)malloc(sizeof(PAY));
if(p3==NULL)
C工资管理系统源代码
#include <>
#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_pay
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);

C工资管理系统源代码精编

C工资管理系统源代码精编

C工资管理系统源代码精编Document number:WTT-LKK-GBB-08921-EIGG-22986#include <>#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;do{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++职工工资管理系统源代码

附录〈源程序〉#i nclude <stdio.h>#i nclude <stdlib.h>#in elude <stri ng.h>struct worker{char n ame[30];char ID[10];int salary1,salary2,salary3;};int dq(struct worker wo[]);void show();void bc(struct 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 wo[100]; // 保存所有的职工信息int Number=0; // 记录总的职工人数void mai n(){int choose=0;while(true){show();prin tf("\t\t====> 请选择:”);sca nf("%d",&choose);system("cls");switch(choose){case 0: exit(O);// 退出break;case 1: add();back();〃添加职工信息break;case 2: see();back();〃查看职工信息break;case 3: search();back();〃查找职工信息break;case 4: del();back();〃删除职工信息break;case 5: statistics。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
/*职工编号*/ char name[15]; /*职工姓名*/ float jbgz; /*基本工资*/ float jj; /*奖金*/ float kk; /*扣款*/ float yfgz; /*应发工资*/ float sk; /*税款*/ float sfgz; /*实发工资*/ }ZGGZ; void menu() /*主菜单*/ { system("cls"); /*调用DOS命令,清屏.与clrscr()功能相同*/ textcolor(10); /*在文本模式中选择新的字符颜色*/ gotoxy(10,5); /*在文本窗口中设置光标*/ cprintf(" The Employee' Salary Management System \n"); gotoxy(10,8); cprintf("**********************Menu*****************************\n"); gotoxy(10,9); cprintf(" * 1 input record 2 delete record *\n"); gotoxy(10,10); cprintf(" * 3 search record 4 modify record *\n"); gotoxy(10,11); cprintf(" * 5 insert record 6 count record *\n"); gotoxy(10,12); cprintf(" * 7 sort reord 8 save record *\n"); gotoxy(10,13); cprintf(" * 9 display record 0 quit system *\n"); gotoxy(10,14); cprintf("********************************************************\n"); /*cprintf()送格式化输出至文本窗口屏幕中*/ }
{ printf("\n\n\n\n\n*******Error:input has wrong! press any key to continue*******\n"); getchar(); } void Nofind() /*输出未查找此职工的信息*/ { printf("\n=====>Not find this employee record!\n"); } /* 作用:用于定位数组中符合要求的记录,并返回保存该记录的数组元 素下标值 ,参数:findmess[]保存要查找的具体内容; nameornum[] 保存按什么在数组中查找; */ int Locate(ZGGZ tp[],int n,char findmess[],char nameornum[]) { int i=0; if(strcmp(nameornum,"num")==0) /*按职工编号查询*/ { while(i<n) { if(strcmp(tp[i].num,findmess)==0) /*若找到findmess值的 职工编号*/ return i; i++; } }else if(strcmp(nameornum,"name")==0) /*按职工姓名查询*/ { while(i<n) { if(strcmp(tp[i].name,findmess)==0) /*若找到findmess 值的姓名*/ return i; i++; } }
return -1; /*若未找到,返回一个整数-1*/ } /*输入字符串,并进行长度验证(长度<lens)*/ void stringinput(char *t,int lens,char *notice) { char n[255]; do{ printf(notice); /*显示提示信息*/ scanf("%s",n); /*输入字符串*/ if(strlen(n)>lens) printf("\n exceed the required length! \n"); /*进行长度校验, 超过lens值重新输入*/ }while(strlen(n)>lens); strcpy(t,n); /*将输入的字符串拷贝到字符串t中*/ } /*输入数值,0<=数值)*/ float numberinput(char *notice) { float t=0.00; do{ printf(notice); /*显示提示信息*/ scanf("%f",&t); /*输入如工资等数值型的值*/ if(t<0) printf("\n score must >=0! \n"); /*进行数值校验*/ }while(t<0); return t; } /*增加职工工资记录*/ int Add(ZGGZ tp[],int n) { char ch,num[10]; int i,flag=0; system("cls"); Disp(tp,n); /*先打印出已有的职工工资信息*/ while(1) /*一次可输入多条记录,直至输入职工编号为0的记录才结束 添加操作*/
{ while(1) /*输入职工编号保证该编号没有被使用,若输入编号为0,则 退出添加记录操作*/ { stringinput(num,10,"input number(press '0'return menu):"); /*格 式化输入编号并检验*/ flag=0; if(strcmp(num,"0")==0) /*输入为0,则退出添加操作,返回主界面 */ { return n; } i=0; while(i<n) /*查询该编号是否已经存在,若存在则要求重新输入一个未 被占用的编号*/ { if(strcmp(tp[i].num,num)==0) { flag=1; break; } i++; } if(flag==1) /*提示用户是否重新输入*/ { getchar(); printf("==>The number %s is existing,try again?(y/n):",num); scanf("%c",&ch); if(ch=='y'||ch=='Y') continue; else return n; } else { break;
} } strcpy(tp[n].num,num); /*将字符串num拷贝到tp[n].num中*/ stringinput(tp[n].name,15,"Name:"); tp[n].jbgz=numberinput("jbgz:"); /*输入并检验基本工资*/ tp[n].jj=numberinput("jiangjin:"); /*输入并检验奖金*/ tp[n].kk=numberinput("koukuan:"); /*输入并检验扣款*/ tp[n].yfgz=tp[n].jbgz+tp[n].jj-tp[n].kk; /*计算应发工资*/ tp[n].sk=tp[n].yfgz*0.12; /*计算税金,这里取应发工资的百分之一十 二*/ tp[n].sfgz=tp[n].yfgz-tp[n].sk; /*计算实发工资*/ saveflag=1; n++; } return n; } /*按职工编号或姓名,查询记录*/ void Qur(ZGGZ tp[],int n) { int select; /*1:按编号查,2:按姓名查,其他:返回主界面(菜 单)*/ char searchinput[20]; /*保存用户输入的查询内容*/ int p=0; if(n<=0) /*若数组为空*/ { system("cls"); printf("\n=====>No employee record!\n"); getchar(); return; } system("cls"); printf("\n =====>1 Search by number =====>2 Search by name\n"); printf(" please choice[1,2]:"); scanf("%d",&select);
void printheader() /*格式化输出表头*/ { printf(HEADER1); printf(HEADER2); printf(HEADER3); } void printdata(ZGGZ pp) /*格式化输出表中数据*/ { ZGGZ* p; p=&pp; printf(FORMAT,DATA); } void Disp(ZGGZ tp[],int n) /*显示数组tp[]中存储的记录,内容为employee结构中定义的 内容*/ { int i; if(n==0) /*表示没有职工工资记录*/ { printf("\n=====>Not employee record!\n"); getchar(); return; } printf("\n\n"); printheader(); /*输出表格头部*/ i=0; while(i<n) /*逐条输出数组中存储的职工信息*/ { printdata(tp[i]); i++; printf(HEADER3); } getchar(); } Void Wrong() /*输出按键错误信息*/
/*这是我开始做课程设计时写的*/ #include "stdio.h" /*标准输入输出函数库*/ #include "stdlib.h" /*标准函数库*/ #include "string.h" /*字符串函数库*/ #include "conio.h" /*屏幕操作函数库*/ #define HEADER1 " -------------------------------ZGGZ--------------------------------------- \n" #define HEADER2 "| number| name | jbgz | jj | kk | yfgz | sk | sfgz | \n" #define HEADER3 "|--------|-----------|--------|--------|--------|-------|--------|--------| \n" #define FORMAT "|%-8s|%-10s |%8.2f|%8.2f|%8.2f|%8.2f|%8.2f|%8.2f| \n" #define DATA p->num,p->name,p->jbgz,p->jj,p->kk,p->yfgz,p>sk,p->sfgz #define END "--------------------------------------------------------------------------- \n" #define N 60 int saveflag=0; /*是否需要存盘的标志变量*/ /*定义与职工有关 的数据结构*/ typedef struct employee /*标记为employee*/
相关文档
最新文档