c语言企业员工管理系统.docx
《c语言企业员工管理系统.docx》由会员分享,可在线阅读,更多相关《c语言企业员工管理系统.docx(22页珍藏版)》请在冰豆网上搜索。
c语言企业员工管理系统
全部源代码:
#include
#include
#include
#include
#defineMAX100
charfilename[20];/*文件名*/
FILE*fp;
intn;/*当前该厂人数*/
structdate/*时间结构体*/
{intyear;
intmouth;
intday;
};
structperson/*员工信息结构体*/
{charname[10];/*姓名*/
intage;/*年龄*/
charjob[10];/*工作*/
charsex[10];/*性别*/
charaddress[20];/*地址*/
charphone[10];/*电话*/
structdatein_time;/*入厂时间*/
}t,worker[MAX];
/*录入模块*/
voidinput()
{inti;
system("cls");//system("cls");
printf("\n\n请输入文件名\n");
scanf("%s",filename);
printf("开始输入员工的信息\n");
printf("\n请输入现有员工人数\n");
scanf("%d",&n);
if((fp=fopen(filename,"w"))==NULL)
{printf("不能建立!
\n");
exit(0);
}
for(i=0;i{printf("第%d个人的信息:
\n",i+1);
printf("姓名\n");
scanf("%s",worker[i].name);
printf("年龄\n");
scanf("%d",&worker[i].age);
printf("工作\n");
scanf("%s",worker[i].job);
printf("性别\n");
scanf("%s",worker[i].sex);
printf("地址\n");
scanf("%s",worker[i].address);
printf("电话\n");
scanf("%s",worker[i].phone);
printf("入厂年\n");
scanf("%d",&worker[i].in_time.year);
printf("入厂月\n");
scanf("%d",&worker[i].in_time.mouth);
printf("入厂日\n");
scanf("%d",&worker[i].in_time.day);
}
printf("录入完毕,按任意键返回主菜单\n");
getch();
for(i=0;ifprintf(fp,"%s%d%s%s%s%s%d-%d-%d\n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day);
fclose(fp);
}
/*输出模块*/
voidoutput()
{inti;
if((fp=fopen(filename,"r"))==NULL)
{printf("暂时未有任何信息,请按任意键返回主菜单进行信息录入\n");
getch();
exit(0);
}
system("cls");
printf("该厂的员工信息:
\n");
printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间\n");
for(i=0;i{fscanf(fp,"%s%d%s%s%s%s%d-%d-%d",worker[i].name,&worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,&worker[i].in_time.year,&worker[i].in_time.mouth,&worker[i].in_time.day);
printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d\n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day);
}
fclose(fp);
printf("输出完毕,按任意键返回主菜单\n");
getch();
}
/*保存模块*/
voidsave()
{inti;
if((fp=fopen(filename,"w"))==NULL)/*打开文件*/
{printf("\n不能打开该文件!
");
exit(0);
}
for(i=0;ifprintf(fp,"%s%d%s%s%s%s%d-%d-%d\n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day);
fclose(fp);
}
/*读取信息*/
voidread_message()
{inti;
printf("输入文件名\n");
scanf("%s",filename);
printf("\n请输入现有员工人数\n");
scanf("%d",&n);
if((fp=fopen(filename,"r"))==NULL)
{printf("暂时未有任何信息,请按任意键返回主菜单进行信息录入\n");
getch();
}
for(i=0;ifscanf(fp,"%s%d%s%s%s%s%d-%d-%d",worker[i].name,&worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,&worker[i].in_time.year,&worker[i].in_time.mouth,&worker[i].in_time.day);
fclose(fp);
}
/*修改模块*/
voidmodify()
{inti,flag,choice;charch,namekey[10];
flag=0;
system("cls");
printf("开始修改\n");
do
{
printf("请输入要修改的员工姓名\n");
scanf("%s",namekey);
for(i=0;i{if(strcmp(worker[i].name,namekey)==0)
{printf("是否修改此人(y/n)\n");
printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间\n");
printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d\n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day);
getchar();/*接收回车*/
ch=getchar();
if(ch=='y')
{printf("****您要修改那一项?
***\n\n");
printf("***1,姓名***\n\n");
printf("***2,年龄***\n\n");
printf("***3,工作***\n\n");
printf("***4,性别***\n\n");
printf("***5,地址***\n\n");
printf("***6,电话***\n\n");
printf("***7,入厂年***\n\n");
printf("***8,入厂月***\n\n");
printf("***9,入厂日***\n\n");
printf("请选择(1-9)\n");
scanf("%d",&choice);
switch(choice)
{case1:
printf("输入修改后的姓名\n");
scanf("%s",worker[i].name);break;
case2:
printf("输入修改后的年龄\n");
scanf("%d",&worker[i].age);break;
case3:
printf("输入修改后的工作\n");
scanf("%s",worker[i].job);break;
case4:
printf("输入修改后的性别\n");
scanf("%s",worker[i].sex);break;
case5:
printf("输入修改后的地址\n");
scanf("%s",worker[i].address);break;
case6:
printf("输入修改后的电话\n");
scanf("%s",worker[i].phone);break;
case7:
printf("输入修改后的入厂年\n");
scanf("%d",&worker[i].in_time.year);break;
case8:
printf("输入修改后的入厂月\n");
scanf("%d",&worker[i].in_time.mouth);break;
case9:
printf("输入修改后的入厂日\n");
scanf("%d",&worker[i].in_time.day);break;
}
printf("修改后的信息\n");
printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间\n");
printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d\n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day);
}
elsebreak;
}
else
if(i==n)printf("此人不存在\n");
}
printf("\n是否继续输入(y/n)\n");
getchar();/*接收回车*/
ch=getchar();
if(ch=='y')
{printf("继续\n");
flag=1;
}
elseflag=0;
}while(flag==1);
printf("修改完毕,按任意键返回主菜单\n");
getch();
}
/*添加模块*/
voidadd()
{inti,flag=0;charch;
system("cls");
printf("\n开始添加新员工\n");
printf("*----------------------------------*\n\n");
do
{i=n;
printf("\n请输入添加职工的信息(姓名,年龄,工作,性别,地址,电话,入厂时间)\n");
printf("姓名\n");
scanf("%s",worker[i].name);
printf("年龄\n");
scanf("%d",&worker[i].age);
printf("工作\n");
scanf("%s",worker[i].job);
printf("性别\n");
scanf("%s",worker[i].sex);
printf("地址\n");
scanf("%s",worker[i].address);
printf("电话\n");
scanf("%s",worker[i].phone);
printf("入厂年\n");
scanf("%d",&worker[i].in_time.year);
printf("入厂月\n");
scanf("%d",&worker[i].in_time.mouth);
printf("入厂日\n");
scanf("%d",&worker[i].in_time.day);
n++;
printf("\n添加成功!
是否继续输入(y/n)\n");
getchar();/*接收回车*/
ch=getchar();
if(ch=='y')
{printf("继续\n");
flag=1;
}
elseflag=0;
}while(flag==1);
printf("添加完毕,按任意键返回主菜单\n");
getch();
}
/*删除模块*/
voiddel()
{inti,flag;charch,namekey[10];
flag=0;
system("cls");
printf("开始删除\n");
do
{printf("请输入要删除员工的名字\n");
scanf("%s",namekey);
for(i=0;iif(strcmp(worker[i].name,namekey)==0)/*查找此人*/
{printf("是否删除此人(y/n)\n");
printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间\n");
printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d\n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day);
getchar();/*接收回车*/
ch=getchar();
if(ch=='y')
{for(;iworker[i]=worker[i+1];
n--;
}
elsebreak;
}
else
if(i==n)
printf("此人不存在\n");
printf("\n是否继续输入(y/n)\n");
getchar();/*接收回车*/
ch=getchar();
if(ch=='y')
{printf("继续\n");
flag=1;
}
elseflag=0;
}while(flag==1);
printf("操作完毕,按任意键返回主菜单\n");
getch();
}
/*更新模块*/
voidrenew()
{inti;
do
{system("cls");
printf("\n\n\n****更新员工信息****\n\n");
printf("按1,添加员工信息\n\n");
printf("按2,删除员工信息\n\n");
printf("按3,修改员工信息\n\n");
printf("按0,返回主菜单\n");
printf("请选择(0-3)\n");
scanf("%d",&i);
switch(i)
{case1:
add();break;
case2:
del();break;
case3:
modify();break;
case0:
break;
}
}while(i!
=0);
save();
}
/*按姓名查找*/
voidname_cha()
{inti,j;charnamekey[10];
j=0;
system("cls");
printf("输入要查询的员工姓名\n");
scanf("%s",namekey);
for(i=0;iif(strcmp(worker[i].name,namekey)==0)/*查找此人*/
{printf("---------员工信息------\n");
printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间\n");
printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d\n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day);
}
elsej++;
if(j==n)
printf("此人不存在\n");
printf("按任意键返回主菜单\n");
getch();
}
/*按年龄查找*/
voidage_cha()
{inti,j;intagekey;
j=0;
system("cls");
printf("输入要查询员工的年龄\n");
scanf("%d",&agekey);
for(i=0;iif(worker[i].age==agekey)
{printf("-------员工信息------\n");
printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间\n");
printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d\n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day);
}
elsej++;
if(j==n)
printf("此人不存在\n");
printf("按任意键返回主菜单\n");
getch();
}
/*按工作查找*/
voidjob_cha()
{inti,j;charjobkey[10];
j=0;
system("cls");
printf("输入要查询的员工职务\n");
scanf("%s",jobkey);
for(i=0;iif(strcmp(worker[i].job,jobkey)==0)
{printf("-------员工信息------\n");
printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间\n");
printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d\n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day);
}
elsej++;
if(j==n)
printf("此人不存在\n");
printf("按任意键返回主菜单\n");
getch();
}
/*查询模块*/
voidinquire()
{inti;
do
{system("cls");
printf("\n\n\n****查询员工信息*****\n\n");
printf("****1,按姓名查询*****\n\n");
printf("****2,按年龄查询*****\n\n");
printf("****3,按工作查询*****\n\n");
printf("****0,返回主菜单\n");
printf("请选择(0-3)\n");
scanf("%d",&i);
switch(i)
{case1:
name_cha();break;
case2:
age_cha();break;
case3:
job_cha();break;
case0:
break;
}
}while(i!
=0);
}
/*排列模块*/
voidline()
{inti,j;
system("cls");
printf("-------按年龄排序-------\n\n");
for(i=0;ifor(j=i+1;jif(worker[i].age>worker[j].age)
{t=worker[i];
worker[i]=worker[j];
worker[j]=t;
}
printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间\n");
for(i=0;iprintf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d\n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time