?? gzgl.h
字號(hào):
struct worker
{
/*職工信息的命名規(guī)則是漢語(yǔ)平行拼音的開(kāi)頭字母組成*/
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) /*創(chuàng)建菜單*/
{
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() /*創(chuàng)建工作區(qū)間*/
{
window(4,4,71,19);
textbackground(GREEN);
clrscr();
window(5,5,70,18);
textbackground(BLUE);
clrscr();
}
void PaintWorkspace() /*繪制工作區(qū)中的文本框和標(biāo)簽*/
{
window(5,5,70,18);
textbackground(BLUE);
textcolor(YELLOW);
clrscr();
gotoxy(3,2);
cprintf("職工號(hào):");
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("補(bǔ)貼:");
gotoxy(3,10);
cprintf("特別獎(jiǎng)金:");
gotoxy(36,10);
cprintf("違紀(jì)處罰:");
gotoxy(3,12);
cprintf("稅金:");
gotoxy(36,12);
cprintf("實(shí)發(fā)工資:");
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);
/*以下是對(duì)p2初始化*/
gotoxy(18,6);
scanf("%s",s);
strcpy(p2->zgh,s); /*對(duì)職工號(hào)賦值*/
gotoxy(51,6);
scanf("%s",s);
strcpy(p2->xm,s);/*對(duì)姓名賦值*/
gotoxy(18,8);
scanf("%s",s);
strcpy(p2->xb,s);/*對(duì)性別賦值*/
gotoxy(51,8);
scanf("%s",s);
strcpy(p2->nl,s);/*對(duì)年齡賦值*/
gotoxy(18,10);
scanf("%s",s);
strcpy(p2->zc,s);/*對(duì)職稱賦值*/
gotoxy(51,10);
scanf("%s",s);
sfgz=sfgz+atoi(s);
strcpy(p2->jbgz,s);/*對(duì)基本工資賦值*/
gotoxy(18,12);
scanf("%s",s);
sfgz=sfgz+atoi(s);
strcpy(p2->zwgz,s);/*對(duì)職位工資賦值*/
gotoxy(51,12);
scanf("%s",s);
sfgz=sfgz+atoi(s);
strcpy(p2->bt,s);/*對(duì)補(bǔ)貼賦值*/
gotoxy(18,14);
scanf("%s",s);
sfgz=sfgz+atoi(s);
strcpy(p2->tbjj,s);/*對(duì)特別獎(jiǎng)金賦值*/
gotoxy(51,14);
scanf("%s",s);
sfgz=sfgz-atoi(s);
strcpy(p2->wjcf,s);/*對(duì)違紀(jì)處罰賦值*/
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));/*對(duì)稅金賦值*/
gotoxy(51,16);
printf("%s",itoa(sfgz,ch,10));
strcpy(p2->sfgz,itoa(sfgz,ch,10)); /*對(duì)實(shí)發(fā)工資賦值*/
/*..................*/
p1->next=p2;
p2->pre=p1;
p2->next=NULL;
(*count)++;
PaintMsgbox();
cprintf("添加完成,請(qǐng)按任意鍵繼續(xù)");
getch();
clrscr();
}
void LoadDate(FILE *fp,struct worker *head,int *count) /*用來(lái)讀取文件中的數(shù)據(jù)*/
{
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)/*保存數(shù)據(jù)到文件中去*/
{
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("輸入你要查找的職工的職工號(hào):");
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("沒(méi)有你要找的記錄,按任意鍵繼續(xù)");
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("刪除成功,請(qǐng)按任意鍵繼續(xù)");
(*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));/*對(duì)稅金賦值*/
gotoxy(51,16);
printf("%s",itoa(sfgz,ch,10));
strcpy(p->sfgz,itoa(sfgz,ch,10)); /*對(duì)實(shí)發(fā)工資賦值*/
PaintMsgbox();
cprintf("修改完成,按任意鍵繼續(xù)");
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("統(tǒng)計(jì)年齡按'a';統(tǒng)計(jì)各種金額按's'");
gotoxy(1,2);
cprintf("統(tǒng)計(jì)平均工資和總工資按'd'");
gotoxy(1,3);
cprintf("對(duì)工資進(jìn)行排序,按其他鍵");
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("青年人數(shù)為:%d",age[0]);
gotoxy(1,2);
cprintf("中年人數(shù)為:%d",age[1]);
gotoxy(1,3);
cprintf("退休人數(shù)為:%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("排序完成,請(qǐng)繼續(xù)");
getch();
clrscr();
break;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -