69,371
社区成员
发帖
与我相关
我的任务
分享
#include "stdio.h"
#include "string.h"
#include "math.h"
#include "stdlib.h"
int size=0;
struct GZ
{long int num;
char name[20];
float jbgz;
float jt;
float ks;
float sfgz;
};
struct GZ s[100];
void Input()
{
FILE *fp;
int n=0;
fp=fopen("e:\\1.txt","r");
while(fscanf(fp,"%ld %s %f %f\n",&s[n].num,s[n].name,&s[n].jbgz,&s[n].jt)!=EOF)
{
n++;
}
fclose(fp);
size=n;
}
void Disp()
{
int n;
printf("\t\t\tNum Name jbgz jt ks sfgz \n");
for(n=0;n<size;n++)
{
printf("\t\t\t%-5ld%-10s%-7.2f%-7.2f%-7.2f%-7.2f\n",s[n].num,s[n].name,s[n].jbgz,s[n].jt,s[n].ks,s[n].sfgz);
printf("\n");
}
}
void Count()/*计算实发工资*/
{
float c,k,a,b;
int n;
for(n=0;n<size;n++)
{
a=s[n].jbgz ;
b=s[n].jt ;
c=a+b;
if(c<=1500) k=0;
else if(c<=2000) k=(float)((c -1500)*0.05);
else if(c>2000) k=(float)((c -1500)*0.05+(c -2000)*0.1);
s[n].sfgz =c-k ;
s[n].ks =k;
printf("\t\t\t%-5ld %-10s %-7.2f %-7.2f %-7.2f %-7.2f\n",s[n].num,s[n].name,s[n].jbgz,s[n].jt,s[n].ks,s[n].sfgz);
printf("\n");
}
}
void Append()/*追加1条职工信息*/
{
int a;
FILE *fp;
printf("please input the people's information that you want to append.\n");
a=size;
fp=fopen("e:\\1.txt","a");
printf("\t\t\tplease re-input the Num Name jbgz jt.\n");
scanf("%ld %s %f %f",&s[a].num,s[a].name,&s[a].jbgz,&s[a].jt);
fwrite(&s[a],sizeof(GZ),1,fp);
fclose(fp);
}
void Modify()/*修改数据*/
{
int a,b,i;
FILE *fp;
printf("please input the people's id number that you want to change.\n");
scanf("%d",&a);
a=a-201700;
if(a>size) printf("sorry the people not exist.\n");
else
{
b=a-1;
fp=fopen("e:\\1.txt","a");
printf("\t\t\tplease re-input the Num Name jbgz jt.\n");
scanf("%ld %s %f %f",&s[b].num,s[b].name,&s[b].jbgz,&s[b].jt);
fseek(fp,i*sizeof(GZ),2);
fwrite(&s[b],sizeof(GZ),1,fp);
fclose(fp);
}
}
void Query()/*查询职工信息*/
{
int a;
printf("please input the people's information that you want to change.\n");
scanf("%d",&a);
a=a-201700;
if(a>size) printf("sorry the people not exist.\n");
else
{
FILE *fp;
float c,k,h,b;
int m=0,n;
printf("\t\t\tNum Name jbgz jt ks sfgz \n");
for(n=0;n<size;n++)
{
h=s[n].jbgz ;
b=s[n].jt ;
c=h+b;
if(c<=1500) k=0;
else if(c<=2000) k=(float)((c -1500)*0.05);
else if(c>2000) k=(float)((c -1500)*0.05+(c -2000)*0.1);
s[n].sfgz =c-k ;
s[n].ks =k;
}
printf("\t\t\t%-5ld %-10s %-7.2f %-7.2f %-7.2f %-7.2f\n",s[a].num,s[a].name,s[a].jbgz,s[a].jt,s[a].ks,s[a].sfgz);
printf("\n");
}
}
void main()
{
int choice;
menu:printf("\t\t\t1.Input employee's information\n");
printf("\t\t\t2.Display employee's information\n");
printf("\t\t\t3.Count\n");
printf("\t\t\t4.Append a employee information\n");
printf("\t\t\t5.Query a employee information\n");
printf("\t\t\t6.Modify employee's intformation\n");
printf("\t\t\t0.Exit system\n\n");
printf("\t\t\tPlease enter choice(0~7)");
scanf("%d",&choice);
switch(choice)
{
case 1:Input();break;
case 2:Disp();break;
case 3:Count();break;
case 4:Append();break;
case 5:Query();break;
case 6:Modify();break;
case 0:exit(0);
}
if(choice<0||choice>6)printf("\n\n\n\t\tplease choose again!\n\n");
goto menu;
}