员工管理系统c语言源代码.docx
《员工管理系统c语言源代码.docx》由会员分享,可在线阅读,更多相关《员工管理系统c语言源代码.docx(15页珍藏版)》请在冰豆网上搜索。
员工管理系统c语言源代码
#include
#include
#defineN10000 /*员工的最大数*/
typedefstructwage
{
floatwage1; /*员工的基本工资*/
floatBonus; /*员工的奖金*/
floattax; /*员工的税金*/
floatS_fee; /*员工的水费*/
floatD_fee; /*员工的电费*/
floatT_fee; /*员工的有线电视费*/
floatQ_fee; /*员工的清洁费*/
floatS_wage; /*员工的实发工资*/
}WAGE;
typedefstructworker
{
charname[10]; /*员工的姓名*/
charID[10]; /*员工的工号*/
intID_P; /*员工的职务代号1----高级工程师 2----中级工程师 3----初级工程师 */
charID_Wage[10]; /*员工的工资卡号*/
chardepart[10]; /*员工的部门*/
intage; /*员工的年龄*/
charsex; /*员工的性别*/
charm_phone[10]; /*员工的手机*/
charH_phone[10]; /*员工的住宅电话*/
WAGEsalary;
}WORK;
WORKwo[N];
intn;/*员工的总数*/
voidmenu();/*员工管理操作主菜单函数声明*/
voidmenu1();/*员工管理操作子菜单函数声明*/
/********************************************************
Author :
GT
CopyRight :
tgao@
functionname :
save
Comments :
保存文件函数
input :
无
output :
无
CreatedDate :
2007/06/01
*********************************************************/
save() /*保存函数,保存n个记录*/
{
intw=1;
FILE*fp;
inti;
system("cls");
if((fp=fopen("work.txt","wb"))==NULL) /*以输出打开方式,在此前的记录被覆盖*/
{
printf("\nCannotopenfile\n");
returnNULL;
}
for(i=0;iif(fwrite(&wo[i],sizeof(structworker),1,fp)!
=1)
{
printf("filewriteerror\n");
w=0;
}
if(w==1)
{
printf("filesaveok!
\n");
}
fclose(fp);
getch();
menu();
}
/********************************************************
Author :
GT
CopyRight :
tgao@
functionname :
load
Comments :
载入文件函数
input :
无
output :
无
CreatedDate :
2007/06/01
*********************************************************/
load() /*加载记录或可以计算记录个数的函数*/
{
FILE*fp;
inti,w;
w=1;
system("cls");
if((fp=fopen("work.txt","rb"))==NULL) /*以输出打开方式,在此前的记录被覆盖*/
{
printf("\nCannotopenfile\n");
w=0;
returnNULL;
}
n=0;
for(i=0;!
feof(fp);i++)
{
fread(&wo[i],sizeof(structworker),1,fp);
n++;
}
n=n-1;
fclose(fp);
if(w==1)
printf("Loadfileok!
");
getch();
menu();
return(i-1); /*返回记录个数*/
}
/********************************************************
Author :
GT
CopyRight :
tgao@
functionname :
no_input
Comments :
输入不能重复的员工编号
input :
i:
表示第i个的员工编号信息 n:
表示比较到第n个员工编号信息
output :
无
CreatedDate :
2007/06/01
*********************************************************/
voidno_input(inti,intn) /*i表示第i个的员工编号信息,n表示比较到第n个员工编号*/
{
intj,k,w1;
do
{
w1=0;
printf("NO.:
");
scanf("%s",wo[i].ID);
for(j=0;wo[i].ID[j]!
='\0';j++) /*员工编号输入函数,作了严格规定*/
if(wo[i].ID[j]<'0'||wo[i].ID[j]>'9') /*判断员工编号是否为数字*/
{
puts("Inputerror!
Onlybemadeupof(0-9).Pleasereinput!
\n");
w1=1;
break;
}
if(w1!
=1)
for(k=0;k /*排除第i个员工编号即你要修改的*/
if(k!
=i&&strcmp(wo[k].ID[j],wo[i].ID[j])==0) /*判断员工编号是否有雷同*/
{
puts("Thisrecordisexist.pleasereinput!
\n");
w1=1;
break;
}
}while(w1==1);
}
/********************************************************
Author :
GT
CopyRight :
tgao@
functionname :
tax
Comments :
工资税金
input :
s:
表示员工工资信息
output :
员工的税金
CreatedDate :
2007/06/01
*********************************************************/
floattax(floats)
{
floattax;
if(s<=800)
tax=0;
elseif(s>800&&s<=1400)
tax=(s-800)*0.05;
elseif(s>1400)
tax=(s-1400)*0.1+600*0.05;
returntax;
}
/********************************************************
Author :
GT
CopyRight :
tgao@
functionname :
input
Comments :
输入一条员工记录
input :
i:
表示第i个的员工信息
output :
无
CreatedDate :
2007/06/01
*********************************************************/
voidinput(inti) /*输入一个记录函数*/
{
intj,sum;
no_input(i,i); /*调用员工编号输入函数*/
printf("name:
");
fflush(stdin);
gets(wo[i].name);
printf("BankID:
");
fflush(stdin);
gets(wo[i].ID_Wage);
printf("grade");
scanf("%d",&wo[i].ID_P);
printf("Department:
");
fflush(stdin);
gets(wo[i].depart);
printf("age:
");
scanf("%d",&wo[i].age);
printf("sex:
");
fflush(stdin);
scanf("%c",&wo[i].sex);
printf("mobilephone");
fflush(stdin);
gets(wo[i].m_phone);
printf("homephone");
fflush(stdin);
gets(wo[i].H_phone);
printf("basicsalary");
scanf("%f",&wo[i].salary.wage1);
wo[i].salary.tax=tax(wo[i].salary.wage1);
printf("Bonus:
");
scanf("%f",&wo[i].salary.Bonus);
printf("waterfee:
");
scanf("%f",&wo[i].salary.S_fee);
printf("dianfee:
");
scanf("%f",&wo[i].salary.D_fee);
printf("QingJiefee:
");
scanf("%f",&wo[i].salary.Q_fee);
printf("TVfee:
");
scanf("%f",&wo[i].salary.T_fee);
wo[i].salary.S_wage=wo[i].salary.wage1+wo[i].salary.Bonus-wo[i].salary.tax-wo[i].salary.D_fee-wo[i].salary.Q_fee-wo[i].salary.S_fee-wo[i].salary.T_fee;
}
/********************************************************
Author :
GT
CopyRight :
tgao@
functionname :
enter
Comments :
输入员工管理系统信息记录
input :
无
output :
无
CreatedDate :
2007/06/01
*********************************************************/
voidenter()
/*输入模块*/
{
inti;
system("cls");
printf("Howmanyrecord(0-%d)?
:
",N);
scanf("%d",&n); /*要输入的记录个数*/
printf("\nEnterdatanow\n\n");
for(i=0;i{
printf("\nInput%dthrecord.\n",i+1);
input(i); /*调用输入函数*/
}
getch();
menu();
}
/********************************************************
Author :
GT
CopyRight :
tgao@
functionname :
printf_one
Comments :
输出一条员工信息记录
input :
i:
表示第i个的员工信息
output :
无
CreatedDate :
2007/06/01
*********************************************************/
voidprintf_one(inti) /*显示一个记录的函数*/
{
intj;
printf("%11s %-6s %-6s %d %d %c %6.2f %s %s",wo[i].ID,wo[i].name,wo[i].ID_Wage,wo[i].ID_P,wo[i].age,wo[i].sex,wo[i].salary.S_wage,wo[i].m_phone,wo[i].H_phone);
}
/********************************************************
Author :
GT
CopyRight :
tgao@
functionname :
printf_one_s
Comments :
输出一条员工工资记录
input :
i:
表示第i个的工资信息
output :
无
CreatedDate :
2007/06/01
*********************************************************/
voidprintf_one_s(inti) /*显示一个记录的函数*/
{
intj;
printf(" %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f",wo[i].salary.wage1,wo[i].salary.S_wage,wo[i].salary.Bonus,wo[i].salary.D_fee,wo[i].salary.Q_fee,wo[i].salary.S_fee,wo[i].salary.T_fee,wo[i].salary.tax);
}
/********************************************************
Author :
GT
CopyRight :
tgao@
functionname :
browse
Comments :
输出员工管理系统信息记录
input :
无
output :
无
CreatedDate :
2007/06/01
*********************************************************/
voidbrowse() /*浏览(全部)模块*/
{
inti,j;
system("cls");
puts("\n--------------------------------------------------------------------");
printf("\n\t工号姓名银行卡号 职称年龄 性别 实发工资手机住宅电话\n");
for(i=0;i{
if((i!
=0)&&(i%10==0)) /*目的是分屏显示*/
{
printf("\n\nPassanykeytocontiune ...");
getch();
puts("\n\n");
}
printf_one(i); /*调用显示一个记录的函数*/
printf("\n");
}
puts("\n--------------------------------------------------------------------");
printf("\tThereare %drecord.\n",n);
getch(); /*按任意健*/
menu();
}
/********************************************************
Author :
GT
CopyRight :
tgao@
functionname :
search_by_ID
Comments :
按工号查找所有员工信息记录
input :
无
output :
输出查找员工编号
CreatedDate :
2007/06/01
*********************************************************/
intsearch_by_ID() /*查找模块*/
{
inti,k;
structworkers;
k=-1;
system("cls");
printf("\n\nEntertheID:
");
scanf("%s",s.ID); /*输入要到达的地方*/
for(i=0;i{
if(strcmp(s.ID,wo[i].ID)==0)
{
k=i; /*找到要修改的记录*/
printf("\n\t工号姓名银行卡号 职称年龄 性别 实发工资手机住宅电话\n");
printf_one(k);
printf("工资信息:
\n");
printf("\n\t基本工资 实发工资 奖金 电费 清洁费 水费 电视费 税金\n");
printf_one_s(k);
break; /*调用显示一个记录的函数*/
}
}
if(k==-1)
{
printf("\n\nNOexist!
");
getch();
menu1();
return-1;
}
else
{
getch();
menu1();
returnk;
}
}
/********************************************************
Author :
GT
CopyRight :
tgao@
functionname :
search_by_age
Comments :
按年龄查找所有员工信息记录
input :
无
output :
输出查找员工编号
CreatedDate :
2007/06/01
*********************************************************/
intsearch_by_age() /*查找模