分类: C/C++
2008-05-31 14:03:57
int mnum=0,fnum=0;//性别人数统计
int expernum=0,doctornum=0,masternum=0,bechelornum=0,othernum=0;//学位人数统计
int dsznum=0,zglnum=0,fzglnum=0,glnum=0,fglnum=0;//职位人数统计
int mishunum=0,jsynum=0,lbnum=0,ygnum=0;
if((fp=fopen(\"employee.txt\",\"r\"))==NULL)
{
printf(\"不能够打开这个文件");
printf(\"按任意键继续");
getch();
return;
}
do
{
fread(&em[i],sizeof(struct employee),1,fp);
if(feof(fp))
break;
num++;
if(strcmp(em[i].sex,\"m\")==0)
mnum++;
if(strcmp(em[i].sex,\"f\")==0)
fnum++;
if(em[i].cult==1)
expernum++;
if(em[i].cult==2)
doctornum++;
if(em[i].cult==3)
masternum++;
if(em[i].cult=4)
bechelornum++;
if(em[i].cult=5)
othernum++;
if(em[i].position==1)//职位统计
dsznum++;
if(em[i].position==2)
zglnum++;
if(em[i].position==3)
fzglnum++;
if(em[i].position==4)
glnum++;
if(em[i].position==5)
fglnum++;
if(em[i].position==6)
mishunum++;
if(em[i].position==7)
jsynum++;
if(em[i].position==8)
lbnum++;
if(em[i].position==9)
ygnum++;
i++;
}while(1);
printf(\"总人数为%d\\n\",num);
printf(\"====性别分类=====\\n\");
printf(\"男人数为%d\\n\",mnum);
printf(\"女人数为%d\\n\",fnum);
printf(\"=====文凭分类=====\\n\");
printf(\"专家数为%d\\n\",expernum);
printf(\"博士数为%d\\n\",doctornum);
printf(\"硕士数为%d\\n\",masternum);
printf(\"学士数为%d\\n\",bechelornum);
printf(\"其他的数为%d\\n\",othernum);
printf(\"=====职位分类========\\n\");
printf(\"董事长数为%d\\n\",dsznum);
printf(\"总经理数为%d\\n\",zglnum);
printf(\"副总经理数为%d\",fzglnum);
printf(\"经理数为%d\",glnum);
printf(\"副经理数为%d\",fglnum);
printf(\"秘书数为%d\",mishunum);
printf(\"技术员数为%d\",jsynum);
printf(\"领班人数为%d\",lbnum);
printf(\"员工数为%d\",ygnum);
fclose(fp);
return;
}
void query()
{
FILE *fp;
int i=0;
char quename[8];
if((fp=fopen(\"employee.txt\",\"r\"))==NULL)
{
printf(\"不能够打开文件,按任意键返回");
getch();
return;
}
printf(\"请你输入要查询的人的姓名");
scanf(\"%s\",quename);
for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++)
{
if(strcmp(em[i].name,quename)==0) /*找到,并显示该职工记录*/
{
printf(\"查询到的职工号或姓名为的信息如下:\\n\");
printf(\"以下是你要查询的人的信息");
printf(\"工号%d\",em[i].num);
printf(\"职位为%d\",em[i].position);
printf(\"为董事长2为总经理3为副总经理");
printf(\"为经理5为副经理6为秘书");
printf(\"为技术员8为领班9为员工");
printf(\"姓名为%s\",em[i].name);
printf(\"性别为%s\",em[i].sex);
printf(\"其中m为男f为女\");
printf(\"文化程度为%d\",em[i].cult);
printf(\"为专家2为博士3为硕士4为学士5为其他");
printf(\"工资为%d\",em[i].salary);
printf(\"身体情况为%d\",em[i].state);
printf(\"");
printf(\"查询完毕,按任意键返回");
getch();
fclose(fp);
return;
}
}
printf(\"没有这样的人,按任意键返回");
getch();
fclose(fp);
return;
}void querysalary()
{
int i;
FILE *fp1,*fp2;
creat();
if((fp1=fopen(\"employee.txt\",\"w+\"))==NULL)
return;
for(i=0;fread(&em[i],sizeof(struct employee),1,fp1)!=0;i++)
{
printf(\"输出结果为:\\n\");
printf(\"工号%d\",em[i].num);
printf(\"职位为%d\",em[i].position);
printf(\"1为董事长2为总经理3为副总经理");
printf(\"4为经理5为副经理6为秘书");
printf(\"7为技术员8为领班9为员工");
printf(\"姓名为%s\",em[i].name[8]);
printf(\"性别为%s\",em[i].sex[2]);
printf(\"其中m为男f为女\");
printf(\"文化程度为%d\",em[i].cult);
printf(\"1为专家2为博士3为硕士4为学士5为其他");
printf(\"工资为%d\",em[i].salary);
printf(\"身体情况为%d\",em[i].state);
printf(\"1好2为一般3为差");
strcpy(emps[i].name,em[i].name);
emps[i].salary=em[i].salary;
}
if((fp2=fopen(\"empsalary.txt\",\"w\"))==NULL)
return;
for(i=0;i
fclose(fp1);
fclose(fp2);
}
void creat()
{
FILE *fp;
if((fp=fopen(\"employee.txt\",\"w+\"))==NULL)
return;
input();
fclose(fp);
}
void communicate()
{
int choicecommunicate;
printf(\"欢迎进入通讯录系统");
printf(\"请你选择操作类型:\\n\");
printf(\"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n\");
printf(\"1为输入通讯录信息");
printf(\"2为查询通讯录信息");
printf(\"3为修改通讯录信息");
printf(\"0为退出通讯录系统");
printf(\"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\n\");
scanf(\"%d\",&choicecommunicate);
switch(choicecommunicate)
{
case 1:
inputcommunicate();
break;
case 2:
querycommunicate();
break;
case 3:
changecommunicate();
break;
case 0:
{
printf(\"谢谢使用再见");
printf(\"按任意键返回");
getch();
return;
}
default:
printf(\"输入有错");
}
} void inputcommunicate()
{
FILE *fp;
int choiceincom=\'y\';
int i=0;
if((fp=fopen(\"empcom.txt\",\"w\"))==NULL)
{
printf(\"不能够打开文件");
printf(\"任意键返回");
getch();
return;
}
printf(\"请你输入通讯录的信息:\\n\");
while(choiceincom==\'y\'||choiceincom==\'Y\')
{
i++;
printf(\"第%d个职工);
printf(\"请你输入姓名:\\n\");
scanf(\"%s\",empc[i].name);
printf(\"请你输入办公室电话号码:\\n\");
scanf(\"%s\",empc[i].officetel);
printf(\"请你输入家庭电话号码:\\n\");
scanf(\"%s\",empc[i].hometel);
printf(\"请你输入手机号码:\\n\");
scanf(\"%s\",empc[i].handtel);
printf(\"请你输入地址:\\n\");
scanf(\"%s\",empc[i].address);
printf(\"是否继续输入?(y/n)\\n\");
choiceincom=getch();
fwrite(&empc[i],sizeof(struct communication),1,fp);
}
if(toupper(choiceincom)==\'N\')
{
fclose(fp);
printf(\"输入完毕,任意键返回");
return;
}
}
void querycommunicate()
{
FILE *fp;
int i=0;
char qcname[8];
if((fp=fopen(\"empcom.txt\",\"r\"))==NULL)
{
printf(\"不能够打开文件,按任意键返回");
getch();
return;
}
printf(\"请你输入要查询的人的姓名:\\n\");
scanf(\"%s\",qcname);
for(i=0;fread(&empc[i],sizeof(struct communication),1,fp)!=0;i++)
{
if(strcmp(empc[i].name,qcname)==0)
{
printf(\"以下为您所要求的信息:\\n\");
printf(\"姓名为%s\\n\",empc[i].name);
printf(\"办公室电话号码为%s\\n\",empc[i].officetel);
printf(\"家庭电话号码为%s\\n\",empc[i].hometel);
printf(\"手机号码为%s\\n\",empc[i].handtel);
printf(\"家庭地址为%s\\n\",empc[i].address);
printf(\"查询完毕,按任意键返回");
getch();
fclose(fp);
return;
}
}
printf(\"没有这样的人,按任意键返回");
getch();
fclose(fp);
return;
}void changecommunicate()
{
FILE *fp;
int i=0;
char chcname[8];
int choicecom;
if((fp=fopen(\"empcom.txt\",\"w+\"))==NULL)
{
printf(\"打不开文件按任意键返回");
getch();
return;
}
printf(\"请你输入你要修改的人的姓名:\\n\");
scanf(\"%s\",chcname);
for(i=0;fread(&empc[i],sizeof(struct communication),1,fp)!=0;i++)
{
if(strcmp(empc[i].name,chcname)==0)
{
printf(\"以下为您所要修改的人的信息:\\n\");
printf(\"姓名为%s\\n\",empc[i].name);
printf(\"办公室电话号码为%s\\n\",empc[i].officetel);
printf(\"家庭电话号码为%s\\n\",empc[i].hometel);
printf(\"手机号码为%s\\n\",empc[i].handtel);
printf(\"家庭地址为%s\\n\",empc[i].address);
printf(\"请你选择要修改的东西:\\n\");
printf(\"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\\n\");
printf(\"1修改办公室电话号码");
printf(\"2修改家庭电话号码");
printf(\"3修改手机电话号码");
printf(\"0退出系统");
printf(\"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\\n\");
scanf(\"%d\",&choicecom);
switch(choicecom)
{
case 1:
changetel1();
break;
case 2:
changetel2();
break;
case 3:
changetel3();
break;
case 0:
return;
default:
printf(\"输入有错");
}
}
}
}
void changetel1()
{
printf(\"参照上面有时间再编");
}
void changetel2()
{
printf(\"参照上面有时间再编");
}
void changetel3()
{
printf(\"参照上面有时间再编");
}