📄 gzgl.h
字号:
struct worker
{
/*职工信息的命名规则是汉语平行拼音的开头字母组成*/
char zgh[10];
char xm[10];
char xb[10];
char nl[5];
char zc[20];
char jbgz[10];
char zwgz[10];
char bt[10];
char tbjj[10];
char wjcf[10];
char sj[10];
char sfgz[10];
struct worker *next;
struct worker *pre;
};
void CreateMenu(char **menu) /*创建菜单*/
{
int i;
textbackground(BLUE);
clrscr( );
window(1,1,80,1);
textbackground(WHITE);
textcolor(BLACK);
clrscr( );
for(i=0;i<8;i++)
{
gotoxy(i*10+1,1);
cprintf("%s",menu[i]);
}
}
void CreateWorkspace() /*创建工作区间*/
{
window(4,4,71,19);
textbackground(GREEN);
clrscr();
window(5,5,70,18);
textbackground(BLUE);
clrscr();
}
void PaintWorkspace() /*绘制工作区中的文本框和标签*/
{
window(5,5,70,18);
textbackground(BLUE);
textcolor(YELLOW);
clrscr();
gotoxy(3,2);
cprintf("职工号:");
gotoxy(36,2);
cprintf("姓名:");
gotoxy(3,4);
cprintf("性别:");
gotoxy(36,4);
cprintf("年龄:");
gotoxy(3,6);
cprintf("职称:");
gotoxy(36,6);
cprintf("基本工资:");
gotoxy(3,8);
cprintf("职位工资:");
gotoxy(36,8);
cprintf("补贴:");
gotoxy(3,10);
cprintf("特别奖金:");
gotoxy(36,10);
cprintf("违纪处罚:");
gotoxy(3,12);
cprintf("税金:");
gotoxy(36,12);
cprintf("实发工资:");
window(18,6,32,6); /*text1*/
textbackground(WHITE);
clrscr();
window(51,6,65,6); /*text2*/
textbackground(WHITE);
clrscr();
window(18,8,32,8); /*text3*/
textbackground(WHITE);
clrscr();
window(51,8,65,8); /*text4*/
textbackground(WHITE);
clrscr();
window(18,10,32,10); /*text5*/
textbackground(WHITE);
clrscr();
window(51,10,65,10); /*text6*/
textbackground(WHITE);
clrscr();
window(18,12,32,12); /*text7*/
textbackground(WHITE);
clrscr();
window(51,12,65,12); /*text8*/
textbackground(WHITE);
clrscr();
window(18,14,32,14); /*text9*/
textbackground(WHITE);
clrscr();
window(51,14,65,14); /*text10*/
textbackground(WHITE);
clrscr();
window(18,16,32,16); /*text11*/
textbackground(WHITE);
clrscr();
window(51,16,65,16); /*text12*/
textbackground(WHITE);
clrscr();
}
void PaintMsgbox()
{
window(25,22,65,24);
textcolor(RED);
textbackground(BLUE);
clrscr();
}
void Add_Record(struct worker *head,struct worker *p,int *count) /*增加一条记录*/
{
int sj=0,sfgz=0;
char *s;
char ch[10]; /*存放中间变量*/
struct worker *p1,*p2;
PaintWorkspace();
for(p1=head;p1->next!=NULL;p1=p1->next);
p2=malloc(sizeof(struct worker));
window(1,1,80, 25);
/*以下是对p2初始化*/
gotoxy(18,6);
scanf("%s",s);
strcpy(p2->zgh,s); /*对职工号赋值*/
gotoxy(51,6);
scanf("%s",s);
strcpy(p2->xm,s);/*对姓名赋值*/
gotoxy(18,8);
scanf("%s",s);
strcpy(p2->xb,s);/*对性别赋值*/
gotoxy(51,8);
scanf("%s",s);
strcpy(p2->nl,s);/*对年龄赋值*/
gotoxy(18,10);
scanf("%s",s);
strcpy(p2->zc,s);/*对职称赋值*/
gotoxy(51,10);
scanf("%s",s);
sfgz=sfgz+atoi(s);
strcpy(p2->jbgz,s);/*对基本工资赋值*/
gotoxy(18,12);
scanf("%s",s);
sfgz=sfgz+atoi(s);
strcpy(p2->zwgz,s);/*对职位工资赋值*/
gotoxy(51,12);
scanf("%s",s);
sfgz=sfgz+atoi(s);
strcpy(p2->bt,s);/*对补贴赋值*/
gotoxy(18,14);
scanf("%s",s);
sfgz=sfgz+atoi(s);
strcpy(p2->tbjj,s);/*对特别奖金赋值*/
gotoxy(51,14);
scanf("%s",s);
sfgz=sfgz-atoi(s);
strcpy(p2->wjcf,s);/*对违纪处罚赋值*/
if(sfgz<=800)
sj=0;
else if(sfgz>800&&sfgz<=1400)
sj=(sfgz-800)*0.05;
else
sj=(sfgz-1400)*0.1;
gotoxy(18,16);
printf("%s",itoa(sj,ch,10));
strcpy(p2->sj,itoa(sj,ch,10));/*对税金赋值*/
gotoxy(51,16);
printf("%s",itoa(sfgz,ch,10));
strcpy(p2->sfgz,itoa(sfgz,ch,10)); /*对实发工资赋值*/
/*..................*/
p1->next=p2;
p2->pre=p1;
p2->next=NULL;
(*count)++;
PaintMsgbox();
cprintf("添加完成,请按任意键继续");
getch();
clrscr();
}
void LoadDate(FILE *fp,struct worker *head,int *count) /*用来读取文件中的数据*/
{
int i;
struct worker *p1,*p2;
fp=fopen("gzgl.txt","r");
fscanf(fp,"%d",count);
p1=head;
for(i=0;i<*count;i++)
{
p2=malloc(sizeof(struct worker));
fscanf(fp,"%s%s%s%s%s%s%s%s%s%s%s%s",p2->zgh,p2->xm,p2->xb,p2->nl,p2->zc,p2->jbgz,p2->zwgz,p2->bt,p2->tbjj,p2->wjcf,p2->sj,p2->sfgz);
p1->next=p2;
p2->pre=p1;
p1=p2;
}
p1->next=NULL;
fclose(fp);
}
void SaveDate(FILE *fp,struct worker *head,int *count)/*保存数据到文件中去*/
{
int i;
struct worker *p;
fp=fopen("gzgl.txt","w");
fprintf(fp,"%d\n",*count);
p=head->next;
for(i=0;i<*count;i++)
{
fprintf(fp,"%s %s %s %s %s %s %s %s %s %s %s %s\n",p->zgh,p->xm,p->xb,p->nl,p->zc,p->jbgz,p->zwgz,p->bt,p->tbjj,p->wjcf,p->sj,p->sfgz);
p=p->next;
}
fclose(fp);
}
void Display(struct worker *p)
{
PaintWorkspace();
window(1,1,80, 25);
gotoxy(18,6);
cprintf("%s",p->zgh);
gotoxy(51,6);;
cprintf("%s",p->xm);
gotoxy(18,8);
cprintf("%s",p->xb);
gotoxy(51,8);
cprintf("%s",p->nl);
gotoxy(18,10);
cprintf("%s",p->zc);
gotoxy(51,10);
cprintf("%s",p->jbgz);
gotoxy(18,12);
cprintf("%s",p->zwgz);
gotoxy(51,12);
cprintf("%s",p->bt);
gotoxy(18,14);
cprintf("%s",p->tbjj);
gotoxy(51,14);
cprintf("%s",p->wjcf);
gotoxy(18,16);
printf("%s",p->sj);
gotoxy(51,16);
printf("%s",p->sfgz);
}
struct worker *Find_Record(struct worker *head,struct worker *ptr)
{
struct worker *p;
char *str;
int flag=0;
PaintMsgbox();
cprintf("输入你要查找的职工的职工号:");
scanf("%s",str);
for(p=head->next;p!=NULL;p=p->next)
if(!strcmp(p->zgh,str))
{
flag=1;
break;
}
if(flag==1)
{
clrscr();
Display(p);
return p;
}
else
{
PaintMsgbox();
cprintf("没有你要找的记录,按任意键继续");
getch();
clrscr();
return ptr;
}
}
void Delete_Record(struct worker *p,int *count)
{
if(*count>1)
{
p->pre->next=p->next;
p->next->pre=p->pre;
PaintMsgbox();
cprintf("删除成功,请按任意键继续");
(*count)--;
getch();
clrscr();
if(p->next!=NULL)
{
p=p->next;
Display(p);
}
else
{
p=p->pre;
Display(p);
}
}
else
{
PaintMsgbox();
cprintf("文件中必须保留一条记录,不能被删除");
getch();
clrscr();
}
}
void Modify_Record(struct worker *p)
{
char ch[10],*s;
int sj=0,sfgz=0;
textcolor(YELLOW);
window(51,10,65,10);
textbackground(WHITE);
clrscr();
window(1,1,80, 25);
gotoxy(51,10);
scanf("%s",s);
strcpy(p->jbgz,s);
sfgz=sfgz+atoi(s);
window(18,12,32,12);
textbackground(WHITE);
clrscr();
window(1,1,80, 25);
gotoxy(18,12);;
scanf("%s",s);
strcpy(p->zwgz,s);
sfgz=sfgz+atoi(s);
window(51,12,65,12);
textbackground(WHITE);
clrscr();
window(1,1,80, 25);
gotoxy(51,12);
scanf("%s",s);
strcpy(p->bt,s);
sfgz=sfgz+atoi(s);
window(18,14,32,14);
textbackground(WHITE);
clrscr();
window(1,1,80, 25);
gotoxy(18,14);;
scanf("%s",s);
strcpy(p->tbjj,s);
sfgz=sfgz+atoi(s);
window(51,14,65,14);
textbackground(WHITE);
clrscr();
window(1,1,80, 25);
gotoxy(51,14);;
scanf("%s",s);
strcpy(p->wjcf,s);
sfgz=sfgz-atoi(s);
if(sfgz<=800)
sj=0;
else if(sfgz>800&&sfgz<=1400)
sj=(sfgz-800)*0.05;
else
sj=(sfgz-1400)*0.1;
gotoxy(18,16);
printf("%s",itoa(sj,ch,10));
strcpy(p->sj,itoa(sj,ch,10));/*对税金赋值*/
gotoxy(51,16);
printf("%s",itoa(sfgz,ch,10));
strcpy(p->sfgz,itoa(sfgz,ch,10)); /*对实发工资赋值*/
PaintMsgbox();
cprintf("修改完成,按任意键继续");
getch();
clrscr();
}
void Tongji(struct worker *head,int count)
{
struct worker *p;
int i,sum=0,avg=0;
int age[3]={0,0,0};
char ch,*s;
PaintMsgbox();
gotoxy(1,1);
cprintf("统计年龄按'a';统计各种金额按's'");
gotoxy(1,2);
cprintf("统计平均工资和总工资按'd'");
gotoxy(1,3);
cprintf("对工资进行排序,按其他键");
switch(getch())
{
case 'A':
case 'a':
for(p=head->next;p!=NULL;p=p->next)
if(atoi(p->nl)<=20)
age[0]=age[0]+1;
else if(atoi(p->nl)&&atoi(p->nl)<=45)
age[1]=age[1]+1;
else
age[2]=age[2]+1;
PaintMsgbox();
gotoxy(1,1);
cprintf("青年人数为:%d",age[0]);
gotoxy(1,2);
cprintf("中年人数为:%d",age[1]);
gotoxy(1,3);
cprintf("退休人数为:%d",age[2]);
getch();
clrscr();
break;
case 'S':
case 's':
PaintMsgbox();
for(p=head->next;p!=NULL;p=p->next)
sum=sum+atoi(p->sj);
gotoxy(1,2);
cprintf("该月的税金为:%d",sum);
getch();
clrscr();
break;
case 'd':
case 'D':
PaintMsgbox();
for(p=head->next;p!=NULL;p=p->next)
sum=sum+atoi(p->sfgz);
avg=sum/count;
gotoxy(1,1);
cprintf("员工平均工资为:%d",avg);
gotoxy(1,2);
cprintf("员工总工资为:%d",sum);
getch();
clrscr();
break;
default:
PaintMsgbox();
for(i=0;i<count-1;i++)
for(p=head->next;p->next!=NULL;p=p->next)
if(atoi(p->sfgz)<atoi(p->next->sfgz))
{
strcpy(s,p->zgh);strcpy(p->zgh,p->next->zgh);strcpy(p->next->zgh,s);
strcpy(s,p->xm);strcpy(p->xm,p->next->xm);strcpy(p->next->xm,s);
strcpy(s,p->xb);strcpy(p->xb,p->next->xb);strcpy(p->next->xb,s);
strcpy(s,p->nl);strcpy(p->nl,p->next->nl);strcpy(p->next->nl,s);
strcpy(s,p->zc);strcpy(p->zc,p->next->zc);strcpy(p->next->zc,s);
strcpy(s,p->jbgz);strcpy(p->jbgz,p->next->jbgz);strcpy(p->next->jbgz,s);
strcpy(s,p->zwgz);strcpy(p->zwgz,p->next->zwgz);strcpy(p->next->zwgz,s);
strcpy(s,p->bt);strcpy(p->bt,p->next->bt);strcpy(p->next->bt,s);
strcpy(s,p->tbjj);strcpy(p->tbjj,p->next->tbjj);strcpy(p->next->tbjj,s);
strcpy(s,p->wjcf);strcpy(p->wjcf,p->next->wjcf);strcpy(p->next->wjcf,s);
strcpy(s,p->sj);strcpy(p->sj,p->next->sj);strcpy(p->next->sj,s);
strcpy(s,p->sfgz);strcpy(p->sfgz,p->next->sfgz);strcpy(p->next->sfgz,s);
}
gotoxy(1,2);
cprintf("排序完成,请继续");
getch();
clrscr();
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -