#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
int saveflag=0;
typedef struct worker
{
char gzkh[20]; /*zhigongkahao*/
char id[20];
char name[20];
char sex;
int gl; /*gongling*/
char department[20];
char level[10]; /*jishuzhicheng*/
char jsbh[20]; /*jishuzhichengbianhao*/
char phone[20];
float jbgz; /*jibengongzi*/
float zwgz; /*zhiwugongzi*/
float yfgz; /*yingfagongzi*/
float sfgz; /*shifagongzi*/
float tax;
float bz; /*buzhu*/
float shuifei;
float dianfei;
float clean; /*qingjiefei*/
float dianshifei; /*dianshishoufei*/
};
typedef struct node
{
struct worker data;
struct node *next;
}Node,*Link;
menu() /*caidanhanshu*/
{
system("cls");
textcolor(12);
gotoxy(10,5);
cprintf("The Worker's Wage System/n");
gotoxy(10,8);
cprintf("******************** menu ********************/n");
gotoxy(10,9);
cprintf("* 1 add 2 chaxun */n");
gotoxy(10,10);
cprintf("* 3 delete 4 save */n");
gotoxy(10,11);
cprintf("* 5 insert 6 modify */n");
gotoxy(10,12);
cprintf("* 7 xianshi 0 exit */n");
gotoxy(10,13);
cprintf("**********************************************/n");
}
Node *locate(Link m,char find[],char fangshi[]) /*dingweihanshu*/
{
Node *r;
if(strcmp(fangshi,"id")==0) /*anzhaoidchaxun*/
{
r=m->next;
while(r)
{
if(strcmp(r->data.id,find)==0)
return r;
r=r->next;
}
}
else if(strcmp(fangshi,"name")==0)
{
r=m->next;
while(r)
{
if(strcmp(r->data.name,find)==0)
return r;
r=r->next;
}
}
}
chaxun(Link m) /*chaxunhanshu*/
{
int choose;
char inputdata[20]; /*cunfangchaxundeneirong*/
Node *p;
if((m->next)==NULL)
{
system("cls");
printf("/nno this worker record!/n");
getchar();
return;
}
system("cls");
printf("1 choose by id 2 choose by name/n");
printf("please input [1/2]/n");
scanf("%d",&choose);getchar();
if(choose==1)
{
printf("please input the data!/n");
scanf("%s",&inputdata);getchar();
p=locate(m,inputdata,"id");
if(p)
{
printf("%4s%4s%4f%4f%4f%4f%4f%4f%4f/n",p->data.gzkh,p->data.name,p->data.sfgz,p->data.shuifei,p->data.dianfei,p->data.clean,p->data.dianshifei,p->data.tax,p->data.sfgz);
printf("enter any key to continue!/n");
getchar();
}
else
{
printf("cannot find the record!/n");
getchar();
}
}
else if(choose==2)
{
printf("please input the data!/n");
scanf("%s",&inputdata);getchar();
p=locate(m,inputdata,"name");
if(p!=NULL)
{
printf("%s%s%f%f%f%f%f%f%f/n",p->data.gzkh,p->data.name,p->data.sfgz,p->data.shuifei,p->data.dianfei,p->data.clean,p->data.dianshifei,p->data.tax,p->data.sfgz);
printf("enter any key to continue!/n");
getchar();
}
else
{
printf("cannot find the record!/n");
getchar();
}
}
}
add(Link m) /*tianjiahanshu*/
{
Node *p,*r,*s;
char numstr[20];
r=m;
while(r->next!=NULL)
{
r=r->next;
}
while(m)
{
p=(Node *)malloc(sizeof(Node));
if(p==NULL)
{
printf("cannot assignment memory space!/n");
exit(0);
}
printf("zhigongkahao:");gets(p->data.gzkh);
if(strcmp(p->data.gzkh,"0")==0)
{
break;
}printf("id:");gets(p->data.id);
printf("name:"); gets(p->data.name);
printf("sex:"); p->data.sex=getchar();getchar();
printf("gongling:");gets(numstr);p->data.gl=atoi(numstr);
printf("department:");gets(p->data.department);
printf("level:");gets(p->data.level);
printf("jishuzhichengbiaohao:");gets(p->data.jsbh);
printf("phone:");gets(p->data.phone);
printf("jibengongzi:");gets(numstr);p->data.jbgz=atof(numstr);
printf("zhiwugongzi:");gets(numstr);p->data.zwgz=atof(numstr);
printf("buzhu:");gets(numstr);p->data.bz=atof(numstr);
printf("shuifei:");gets(numstr);p->data.shuifei=atof(numstr);
printf("dianfei:");gets(numstr);p->data.dianfei=atof(numstr);
printf("qingjiefei:");gets(numstr);p->data.clean=atof(numstr);
printf("dianshifei:");gets(numstr);p->data.dianshifei=atof(numstr);
p->data.yfgz=p->data.jbgz+p->data.zwgz+p->data.bz;
if(p->data.yfgz<800) p->data.tax=0;
else if(p->data.yfgz<=1400) p->data.tax=(p->data.yfgz-800)*0.05;
else p->data.tax=(p->data.yfgz-1400)*0.1;
p->data.sfgz=p->data.jbgz+p->data.zwgz+p->data.bz-(p->data.tax+p->data.shuifei+p->data.dianfei+p->data.clean+p->data.dianshifei);
p->next=NULL;
r->next=p;
r=p;
saveflag=1;
}
}
delete(Link m) /*shanchuhanshu*/
{
int choose;
Node *p,*r;
char find[20];
if(m->next==NULL)
{
system("cls");
printf("there is no record!/n");
getchar();
return;
}
system("cls");
printf(" 1 delete by id 2 delete by name /n");
printf("please input [1/2]:/n");
scanf("%d",&choose);getchar();
if(choose==1)
{
printf("please input the existing id!/n");
scanf("%s",find);getchar();
p=locate(m,find,"id");
if(p!=NULL)
{
r=m;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("delete success!/n");
getchar();
saveflag=1;
}
else
{
printf("cannot find the id!/n");
getchar();
}
}
else if(choose==2)
{
printf("please input the existing name!/n");
scanf("%s",find);getchar();
p=locate(m,find,"name");
if(p!=NULL)
{
r=m;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("delete success!/n");
getchar();
saveflag=1;
}
else
{
printf("cannot find the name!/n");
getchar();
}
}
}
xianshi(Link m) /*xianshihanshu*/
{
Node *p;
p=m->next;
if(p==NULL)
{
printf("there is not the record!/n");
getchar();
return;
}
while(p)
{
printf("/t%4s/t%4s/t%4f/t%4f/t%4f/t%4f/t%4f/t%4f/t%4f/n",
p->data.gzkh,p->data.name,p->data.yfgz,p->data.shuifei,p->data.dianfei,p->data.clean,p->data.dianshifei, p->data.tax,p->data.sfgz);
p=p->next;
}
getch();
}
modify(Link m) /*xiugaihanshu*/
{
Node *p;
char find[20];
char numstr[20];
if(m->next==NULL)
{
system("cls");
printf("there is not the record!/n");
getchar();
return;
}
system("cls");
printf("please input the id you want to modify!/n");
gets(find);
p=locate(m,find,"id");
if(p)
{
strcpy(p->data.id,find);
printf("please input the data!/n");
printf("name:"); gets(p->data.name);
printf("sex:"); p->data.sex=getchar();getchar();
printf("gongling:");gets(numstr);p->data.gl=atoi(numstr);
printf("department:");gets(p->data.department);
printf("level:");gets(p->data.level);
printf("jishuzhichengbiaohao:");gets(p->data.jsbh);
printf("phone:");gets(p->data.phone);
printf("jibengongzi:");gets(numstr);p->data.jbgz=atof(numstr);
printf("zhiwugongzi:");gets(numstr);p->data.zwgz=atof(numstr);
printf("buzhu:");gets(numstr);p->data.bz=atof(numstr);
printf("shuifei:");gets(numstr);p->data.shuifei=atof(numstr);
printf("dianfei:");gets(numstr);p->data.dianfei=atof(numstr);
printf("qingjiefei:");gets(numstr);p->data.clean=atof(numstr);
printf("dianshifei:");gets(numstr);p->data.dianshifei=atof(numstr);
p->data.yfgz=p->data.jbgz+p->data.zwgz+p->data.bz;
if(p->data.yfgz<800) p->data.tax=0;
else if(p->data.yfgz<=1400) p->data.tax=(p->data.yfgz-800)*0.05;
else p->data.tax=(p->data.yfgz-1400)*0.1;
p->data.sfgz=p->data.jbgz+p->data.zwgz+p->data.bz-(p->data.tax+p->data.shuifei+p->data.dianfei+p->data.clean+p->data.dianshifei);
printf("modify success!/n");
saveflag=1;
}
else
{
printf("not modify!/n");
}
}
save(Link m)
{
FILE *fp;
Node *p;
int count=0;
fp=fopen("d://hello.txt","wb");
if(fp==NULL)
{
printf("cannot open the file !/n");
getchar();
return;
}
p=m->next;
while(p!=NULL)
{
fwrite(p,sizeof(Node),1,fp);
p=p->next;
count++;
}
if(count>0)
{
printf("the file is saved succefully!/n");
getchar();
saveflag=0;
}
else
{
system("cls");
printf("there is not new data or save is faular!/n");
getchar();
}
fclose(fp);
}
insert(Link m) /*charuhanshu*/
{
Link p,newinfo;
char ch;
char find[20];
char numstr[20];
system("cls");
printf("please input the find[20] !/n");
gets(find);
newinfo=(Node *)malloc(sizeof(Node));
if(newinfo==NULL)
{
printf("there is not memory!/n");
getchar();
return;
}
printf("please input the insert data!/n");
printf("zhigongkahao:");gets(newinfo->data.gzkh);
printf("id:");gets(newinfo->data.id);
printf("name:"); gets(newinfo->data.name);
printf("sex:"); newinfo->data.sex=getchar(); getchar();
printf("gongling:");gets(numstr);newinfo->data.gl=atoi(numstr);
printf("department:");gets(newinfo->data.department);
printf("level:");gets(newinfo->data.level);
printf("jishuzhichengbiaohao:");gets(newinfo->data.jsbh);
printf("phone:");gets(newinfo->data.phone);
printf("jibengongzi:");gets(numstr);newinfo->data.jbgz=atof(numstr);
printf("zhiwugongzi:");gets(numstr);newinfo->data.zwgz=atof(numstr);
printf("buzhu:");gets(numstr);newinfo->data.bz=atof(numstr);
printf("shuifei:");gets(numstr);newinfo->data.shuifei=atof(numstr);
printf("dianfei:");gets(numstr);newinfo->data.dianfei=atof(numstr);
printf("qingjiefei:");gets(numstr);newinfo->data.clean=atof(numstr);
printf("dianshifei:");gets(numstr);newinfo->data.dianshifei=atof(numstr);
newinfo->data.yfgz=newinfo->data.jbgz+newinfo->data.zwgz+newinfo->data.bz;
if(newinfo->data.yfgz<800) newinfo->data.tax=0;
else if(newinfo->data.yfgz<=1400) newinfo->data.tax=(newinfo->data.yfgz-800)*0.05;
else newinfo->data.tax=(newinfo->data.yfgz-1400)*0.1;
newinfo->data.sfgz=newinfo->data.jbgz+newinfo->data.zwgz+newinfo->data.bz-(newinfo->data.tax+newinfo->data.shuifei+newinfo->data.dianfei+newinfo->data.clean+newinfo->data.dianshifei);
printf("modify success!/n");
saveflag=1;
p=m->next;
while(m)
{
if(strcmp(p->data.id,find)==0)
{
newinfo->next=p->next;
p->next=newinfo;
break;
}
p=p->next;
}
getchar();
}
void main() /*zhuhanshu*/
{
Link m;
FILE *fp;
int choose;
char ch;
int count=0;
Node *p,*r;
m=(Node*)malloc(sizeof(Node));
if(m==NULL)
{
printf("shen qing shi bai!/n");
return;
}
m->next=NULL;
r=m;
fp=fopen("d://hello.txt","wb+");
if(fp==NULL)
{
printf("error!/n");
getchar();
}
while(feof(fp)==0)
{
if(fp==NULL)
{
printf("cannot open the file!/n");
getch();
exit(0);
}
while(fread(p,sizeof(Node),1,fp)==1)
{
p->next=NULL;
r->next=p;
r=p;
count++;
}
}
fclose(fp);
printf("the total number is :%d/n",count);
menu();
while(m)
{
system("cls");
menu();
p=r;
printf("please input your number (0-7):/n");
scanf("%d",&choose);getchar();
if(choose==0)
{
if(saveflag==1)
{
getchar();
printf("Do you want to save the file?(y/n):");
scanf("%c",&ch);getchar();
if(ch=='y'||ch=='Y')
save(m);
}
printf("Thank you for useing it!");
getchar();
break;
}
switch(choose)
{
case 1:add(m);break;
case 2:chaxun(m);break;
case 3:delete(m);break;
case 4:save(m);break;
case 5:insert(m);break;
case 6:modify(m);break;
case 7:xianshi(m);break;
default:break;
}
}
}