#include
#include
#include
#define LEN sizeof(struct teacher)
typedef struct date
{ int year;
int month;
int day;
}SDATE;
typedef struct teacher
{long num;
char name[10];
char sex[5];
SDATE born_time;
SDATE work_time;
long salary;
char academy[10];
char post[10];
char degree[10];
}TE;
void creat(); //初始化老师信息
void add();//对文件进行增加信息
void del();//删除信息
void modify();//修改信息
void search();//对信息进行查询
void statis();//对信息进行统计
void sort();//排序
void saveTeachers();//保存老师信息
void searchName();//按姓名查询
void searchNum();//按编号查询
void searchAcd();//按学院查询
void searchPost();//按职称查询
void searchWtime();//按工作时间查询
void outputTeacher(int);//输出指定教师信息
void statis1980();
void statisPost();
void statisDe();
void statisSa();
TE Teacher[100];
int tn;//老师数量
//主函数
void main()
{
int m;
while(1)
{printf("\n **********高校教师人事管理系统**********\n");
printf("\n** 创建信息文件,请按1 **");
printf("\n** 追加教师信息,请按2 **");
printf("\n** 删除教师信息,请按3 **");
printf("\n** 修改教师信息,请按4 **");
printf("\n** 查询教师信息,请按5 **");
printf("\n** 统计教师信息,请按6 **");
printf("\n** 退出系统, 请按0 **\n");
scanf("%d",&m);
getchar();
switch(m)
{
case 1: creat();
break;
case 2: add();
break;
case 3: del();
break;
case 4: modify();
break;
case 5: search();
break;
case 6: statis();
break;
case 0: exit(0);break;
default:printf("按键错误,请重新输入!\n");
}//end switch
}//end while
}
//建立链表,排序,写入文件
void creat(void)
{
int flag=1;
while(flag){
printf("\n请输入编号\n");
scanf("%ld",&Teacher[tn].num);
printf("\n请输入姓名\n");
scanf("%s",Teacher[tn].name);
printf("\n请输入性别\n");
scanf("%s",&Teacher[tn].sex);
printf("\n请输入出生日期\n");
scanf("%d%d%d",&Teacher[tn].born_time .year,&Teacher[tn].born_time.month,&Teacher[tn].born_time.day);
printf("\n请输入参加工作时间\n");
scanf("%d%d%d",&Teacher[tn].work_time.year,&Teacher[tn].work_time.month,&Teacher[tn].work_time.day);
printf("\n请输入工资\n");
scanf("%d",&Teacher[tn].salary);
printf("\n
请输入学院\n");
scanf("%s",Teacher[tn].academy);
printf("\n请输入职称(助教、讲师、副教授、教授)\n");
scanf("%s",Teacher[tn].post);
printf("\n请输入学位(学士、硕士、博士)\n");
scanf("%s",Teacher[tn].degree);
tn++;
printf("继续输入?yes 1 no 0\n");
scanf("%d",&flag);
getchar();
}
sort();
saveTeachers();
}
//===================================排序==============================
void sort()
{
int i,j, k;
TE temp;
for(i=0;i
k=i;
for(j=i+1;j
k=j;
if(k!=i)
{temp=Teacher[i];Teacher[i]=Teacher[k];Teacher[k]=temp;}
}//end for
}
//=======================保存老师信息===================================
void saveTeachers()
{
FILE *fp;
fp=fopen("teacher.dat","wb+");
if(!fp)
{printf("file can't open!\n"); return;}
if(fwrite(Teacher,LEN,tn,fp)==tn)
printf("老师信息保存成功!\n");
}
//========================================================================
//输出
void outputTeacher(int i)
{
printf("编号为%ld\n",Teacher[i].num);
printf("姓名为%s\n",Teacher[i].name);
printf("性别为%s\n",Teacher[i].sex);
printf("出生日期为%4d.%2d.%2d\n",Teacher[i].born_time.year,Teacher[i].born_time.month,Teacher[i].born_time.day);
printf("参加工作时间为%4d.%2d.%2d\n",Teacher[i].work_time.year,Teacher[i].work_time.month,Teacher[i].work_time.day);
printf("工资为%d\n",Teacher[i].salary);
printf("学院为%s\n",Teacher[i].academy);
printf("职称为%s\n",Teacher[i].post);
printf("学位为%s\n",Teacher[i].degree);
}
//=====================添加================
void add()
{
creat();
}
void del()
{
long num;
int flag=1,f;
int i,j;
while(flag){
printf("编号:\n");
scanf("%ld",&num);
for(i=0;i
if(num==Teacher[i].num)
break;
}// end for
if(i>=tn)
printf("编号输入错误!\n");
else{
outputTeacher(i);//显示删除的教师信息
printf("确认删除?yes 1 no 0\n");
scanf("%d",&f);
if(f==1)
{
for(j=i;j
tn--;
}//end if
}//end else
printf("继续删除其他教师?yes 1 no 0\n");
scanf("%d",&flag);
}//end while
sort();
saveTeachers();
}
//==============================================================
void modify(){
int i,num,select;
int flag=1,f=1;
while(flag)
{
printf("请输入修改教师的编号!\n");
scanf("%ld",&num);
for(i=0;i
if(num==Teacher[i].num)
break;
}// end for
if(i>=tn)
printf("编号输入错误!\n");
else{
while(f){
printf(" 1.修改编号\n");
printf("
2.修改姓名\n");
printf(" 3.修改性别\n");
printf(" 4.修改出生日期\n");
printf(" 5.修改参加工作时间\n");
printf(" 6.修改工资\n");
printf(" 7.修改学院\n");
printf(" 8.修改职称\n");
printf(" 9.修改学位\n");
scanf("%d",&select);
getchar();
switch(select)
{
case 1:
printf("新编号:\n");
scanf("%ld",&Teacher[i].num);
f=0;
break;
case 2:
printf("新姓名:\n");
scanf("%s",Teacher[i].name);
f=0;
break;
case 3:
printf("新性别:\n");
scanf("%s",Teacher[i].sex);
f=0;
break;
case 4:
printf("新出生日期:\n");
scanf("%d%d%d",&Teacher[tn].born_time .year,&Teacher[tn].born_time.month,&Teacher[tn].born_time.day);
f=0;
break;
case 5:
printf("新工作时间:\n");
scanf("%d%d%d",&Teacher[tn].work_time.year,&Teacher[tn].work_time.month,&Teacher[tn].work_time.day);
f=0;
break;
case 6:
printf("新工资:\n");
scanf("%d",&Teacher[i].salary );
f=0;
break;
case 7:
printf("新学院:\n");
scanf("%s",Teacher[i].academy );
f=0;
break;
case 8:
printf("新职称:\n");
scanf("%s",Teacher[i].post );
f=0;
break;
case 9:
printf("新学位:\n");
scanf("%s",Teacher[i].degree );
f=0;
break;
default:printf("按键错误,重新输入\n");
}//end switch
}//end while
}//end else
}//end while
sort();
saveTeachers();
}//
void search()
{int i,j;
int flag=1,f=1;
long num;
while(flag){
printf("\n 按编号查询请输入1\n");
printf("\n 按精确姓名查询请输入2\n");
printf("\n 按学院查询请输入3\n");
printf("\n 按职称查询请输入4\n");
printf("\n 按参加工作时间查询请输入5\n");
printf("\n 退出查询输入0\n");
scanf("%d",&i);
getchar();
switch(i){
case 1:searchNum();break;
case 2:searchName();break;
case 3:searchAcd();break;
case 4:searchPost();break;
case 5:searchWtime();break;
case 0:return;
default:printf("按键错误,请重新输入!\n");f=0;
}//end switch
if(f){
printf("继续查询?yes 1 no 0\n");
scanf("%d",&flag);
getchar();
}//end if
}//end while
}
//==================================================================================================
//=======================searchNum===========
void searchNum(){
long num;
int i;
printf("编号:\n");
scanf("%ld",&num);
for(i=0;i
break;
}//end for
if(i>=tn)
{printf("没有该教师信息!\n");return;}
outputTeacher(i);
}
//=======================searchName===============
void searchName(){
char name[10];
int i;
printf("名字:\n");
scanf("%s",name);
for(i=
0;i
break;
}//end for
if(i>=tn)
{printf("没有该教师信息!\n");return;}
outputTeacher(i);
}
//========================searchAcd============
void searchAcd(){
char acd[10];
int i;
printf("学院:\n");
scanf("%s",acd);
for(i=0;i
break;
}//end for
if(i>=tn)
{printf("没有该教师信息!\n");return;}
outputTeacher(i);
}
//==================searchPost================
void searchPost(){
char post[10];
int i;
printf("职称:\n");
scanf("%s",post);
for(i=0;i
break;
}//end for
if(i>=tn)
{printf("没有该教师信息!\n");return;}
outputTeacher(i);
}
//=================searchWtime=============
void searchWtime()
{
SDATE wTime;
int i;
printf("工作时间:如(2001 10 2)\n");
scanf("%d%d%d",&wTime.year,&wTime.month ,&wTime.day );
for(i=0;i
break;
}//end for
if(i>=tn)
{printf("没有该教师信息!\n");return;}
outputTeacher(i);
}
//========================================
void statis()
{
int i;
printf("1.统计1980年以后出生的教师人数,及80后教师比例!\n");
printf("2.统计各职称岗位的教师人数是多少,计算高级职称(包括副教授和教授)的比例\n");
printf("3.统计各学位的教师人数是多少,计算拥有博士学位的教师占教师总数的比例\n");
printf("4.计算教师的平均工资,并输出\n");
scanf("%d",&i);
getchar();
switch(i){
case 1:statis1980();break;
case 2:statisPost();break;
case 3:statisDe();break;
case 4:statisSa();break;
default :printf("按键错误!\n");
}//end switch
}
//=============statis1980==========================
void statis1980()
{int num=0,i;
float bl;
for(i=0;i
num++;
}
bl=(float)num/tn;
printf("80后教师人数为:%d,占教师总数比例为:%f",num,bl);
}
//==============statisPost===========================
void statisPost()
{int post[4]={0};
int i;
float bl;
for(i=0;i
if(strcmp(Teacher[i].academy,"讲师")==0) post[1]++;
if(strcmp(Teacher[i].academy,"副教授")==0) post[2]++;
if(strcmp(Teacher[i].academy,"教授")==0) post[3]++;
}
bl=(float)post[2]/post[3];
printf("助教人数为:%d\n",post[0]);
printf("讲师人数为:%d\n",post[1]);
printf("副教授人数为:%d\n",post[2]);
printf("教授人数为;%d\n",post[3]);
printf("副教授和教授比例为:%f\n",bl);
}
//=============
===statisDe============================
void statisDe()
{int deg[3]={0};
int i;
float bl;
for(i=0;i
if(strcmp(Teacher[i].degree,"硕士")==0) deg[1]++;
if(strcmp(Teacher[i].degree,"博士")==0) deg[2]++;
}
bl=(float)deg[2]/tn;
printf("学士人数为:%d\n",deg[0]);
printf("硕士人数为:%d\n",deg[1]);
printf("博士人数为:%d\n",deg[2]);
printf("博士占教师总数的比例为;%f\n",bl);
}
//=====================statisSa===========
void statisSa()
{int i;
long sal=0;
float ave;
for(i=0;i
printf("平均工资为:%f\n",ave);
}