FILE *fp1; //存教师个人信息数据文件,文件的头指针
/*******************************定义函数块(函数的******************************/
void sysmeun(struct allteainfo *); //系统主菜单显示 void infomeun(struct allteainfo *);//教学信息管理菜单
void inputinfo(struct allteainfo *); //教师信息录入 void printall(struct allteainfo *tea);//教师信息输出
void deleinfo(struct allteainfo *);//删除 void lookinfo(struct allteainfo *); //查寻
void lookinfobynumber(struct allteainfo *tea);//按职工号查询
void sortnumber(struct allteainfo *tea);//对职工号排序(从小到大) void lookinfobyname(struct allteainfo *tea);//按姓名查询 void lookinfobyscore(struct allteainfo *tea);//按课程查询
void addinfo(struct allteainfo *tea);//插入
void sortpingfen(struct allteainfo *);//排序 按综合评分
/********************定义结构体*******************************/ struct teainfo { char name[10];//姓名 int number;//职工号 char score[10];//第一门课程 char score2[10];//第二门课程 char score3[10];//第三门课程 char title[10];//职称 char sex[5];//性别 float pingfen;//教学成果综合评分 };
声明 )
struct allteainfo { struct teainfo teacher1;//现在用结构体 // struct teainfo teacher2;//备用结构体(在此程序中未用) };
/************************主函数***********************/ void main() { struct allteainfo stu[100],*tea;//stu[100]为结构体型数组 *tea为结构体型指针 tea=stu; sysmeun(tea);//调用主菜单函数 }
/*********************主菜单***********************/ void sysmeun(struct allteainfo *tea) { int a; do { system(\"cls\"); printf(\"\\n\\n\\n\\n\\****************************************\\n\\n\"); printf(\"\\ 1、教师信息管理 \\n\"); printf(\"\\ 2、退 出 系 统 \\n\\n\"); printf(\"\\****************************************\\n\\n\"); printf(\"\\请输入正确的选项:\"); scanf(\"%d\从键盘读取a 值 switch(a) {
case 1:infomeun(tea);break; case 2:break; default:system(\"cls\");printf(\"\\n\\n\\n\\n\\n\\n\\n\\\输入错误,请按任意键返回!\");getch(); } }while(a!=2); system(\"cls\");//清屏 }
/*********************教师信息管理菜单***********************/ void infomeun(struct allteainfo *tea) {
int a; do { system(\"cls\"); printf(\"\\n\\n\\n\\n\\n\\****************************************\\n\\n\"); printf(\"\\0--------------输出\\n\"); printf(\"\\1--------------查询\\n\"); printf(\"\\2--------------排序(按综合评分)\\n\"); printf(\"\\3--------------排序(按职工号)\\n\"); printf(\"\\4--------------插入\\n\"); printf(\"\\5--------------删除\\n\\n\"); printf(\"\\6--------------教师信息录入(即教师信息的初始化)\\n\"); printf(\"\\7--------------退出教师信息管理系统\\n\\n\"); printf(\"\\****************************************\\n\\n\"); printf(\"\\\请输入正确的选项:\"); scanf(\"%d\ switch(a) { case 0:printall(tea);break; case 1:lookinfo(tea);break; case 2:sortpingfen(tea);break; case 3:sortnumber(tea);break; case 4:addinfo(tea);break; case 5:deleinfo(tea);break; case 6:inputinfo(tea);break; case 7:break; default:system(\"cls\");printf(\"\\n\\n\\n\\n\\输入错误,请按任意键返回!\");getch(); } }while(a!=7); return; }
/********************************教师信息录入 ******************/ void inputinfo(struct allteainfo *tea) { int i; char ch; if((fp1=fopen(\"student.dat\打开文件 并 判断是否能成功打开,文件名为student ,打开方式为wb (只写 ) { printf(\"\\\Can not open file!\\n\"); getch(); exit(1); }
rewind(fp1); //定位文件头开始 for(i=0;i<100,ch!='N'&&ch!='n';i++)//判断ch ,若ch不等于n,也不等于N ,则执行以下循环 { system(\"cls\");//清屏 printf(\"\\n\\n\\正在录入第%d个教师的信息…………\\n\ printf(\"***************************************************************\\n\"); printf(\"\请输入第%d个教师的姓名:\ printf(\"\请输入第%d个教师的性别:\ printf(\"\请输入第%d个教师的职称:\ printf(\"\请输入第%d个教师的职号:\ printf(\"\请输入第%d个教师的教学成果综合分:\ printf(\"\请输入第%d个教师的第一门程:\ printf(\"\请输入第%d个教师的第二门程:\ printf(\"\请输入第%d个教师的第三门课程:\ printf(\"\\n\\n\\n\"); fwrite(&tea[i].teacher1,sizeof(struct teainfo),1,fp1);//将数据写入文件 printf(\"\\n\是否继续录入下一个教师信息(Y/N):\"); scanf(\"%c\ getchar();//接收回车,避免影响输入 } printf(\"\\n\录入完毕,请按任意键返回!\"); getch(); fclose(fp1); return;//返回教师信息管理菜单 }
/*****************删除********************************/ void deleinfo(struct allteainfo *tea) { int i,count; char ch,name[10]; if((fp1=fopen(\"student.dat\打开文件 { printf(\"Can not open file!\\n\"); getch(); exit(1);
工评课课 } rewind(fp1); //定位文件头开始 for(count=0;fread(&tea[count].teacher1,sizeof(struct teainfo),1,fp1)==1;count++) continue;//计算教师信息的教师总数 fclose(fp1);
while(ch!='N'&&ch!='n') { system(\"cls\"); printf(\" \\n\\n\\n\\请输入要删除的教师的姓名:\"); gets(name);
for(i=0;i /*****************查询********************************/ void lookinfo(struct allteainfo *tea) { int a; do { system(\"cls\"); printf(\"\\n\\n\\n\\****************************************\\n\\n\"); printf(\"\ 1----------按职工号查询 \\n\"); printf(\"\ 2----------按姓名查询 \\n\"); printf(\"\ 3----------按课程查询 \\n\"); printf(\"\ 4----------退出查询功能 \\n\\n\"); printf(\"\\****************************************\\n\\n\"); printf(\"\\请输入正确的选项:\"); scanf(\"%d\ switch(a) { case 1:lookinfobynumber(tea);break; case 2:lookinfobyname(tea);break; case 3:lookinfobyscore(tea);break; case 4:break; default:system(\"cls\");printf(\"\\n\\n\\n\\n\\输入错误,请按任意键返回!\");getch(); } }while(a!=4); return; } void lookinfobynumber(struct allteainfo *tea)//按职工号查询 { int count,low,high,mid,a,number; char ch; if((fp1=fopen(\"student.dat\打开文件 { printf(\"Can not open file!\\n\"); getch(); exit(1); } rewind(fp1); //定位文件头开始 for(count=0;fread(&tea[count].teacher1,sizeof(struct teainfo),1,fp1)==1;count++) continue;//计算教师信息的教师总数 while(ch!='N'&&ch!='n') { void sortnumber(struct allteainfo *tea);//采用二分查找前先对数据进行从小到大的排序 system(\"cls\"); printf(\"\\n\\n\\请输入要查找的信息的教师职工号:\"); scanf(\"%d\ low=0;high=count;// 二分查找(也叫 折半查找) while (low<=high) { mid=(low+high)/2; if(number==tea[mid].teacher1.number) { a=1; break; } else if(number printf(\"\\n\\查找完毕,请按任意键返回!\"); getch(); fclose(fp1); return;//返回教师信息管理菜单 } /********************************职工号排序 递增序列******************/ void sortnumber(struct allteainfo *tea) { int i,j,k,count; struct allteainfo t; if((fp1=fopen(\"student.dat\打开文件 打开方式为rb (只读) { printf(\"Can not open file!\\n\"); getch(); exit(1); } rewind(fp1); //定位文件头开始 for(count=0;fread(&tea[count].teacher1,sizeof(struct teainfo),1,fp1)==1;count++) continue;//计算教师信息的教师总数 system(\"cls\"); for(i=0;i tea[k]=t; } } } void lookinfobyname(struct allteainfo *tea)//按名字查询 { int i,count; char ch,name[10]; if((fp1=fopen(\"student.dat\打开文件 { printf(\"Can not open file!\\n\"); getch(); exit(1); } rewind(fp1); //定位文件头开始 for(count=0;fread(&tea[count].teacher1,sizeof(struct teainfo),1,fp1)==1;count++) continue;//计算教师信息的教师总数 while(ch!='N'&&ch!='n') { system(\"cls\"); printf(\"\\n\\n\\请输入要查找的信息的教师姓名:\"); gets(name); for(i=0;i printf(\"\\n\查找完毕,请按任意键返回!\"); getch(); fclose(fp1); return;//返回教师信息管理菜单 } void lookinfobyscore(struct allteainfo *tea)//按课程查询 { int i,count; char ch; char score[10]; if((fp1=fopen(\"student.dat\打开文件 { printf(\"Can not open file!\\n\"); getch(); exit(1); } rewind(fp1); //定位文件头开始 for(count=0;fread(&tea[count].teacher1,sizeof(struct teainfo),1,fp1)==1;count++) continue;//计算教师信息的教师总数 while(ch!='N'&&ch!='n') { system(\"cls\"); printf(\"\\n\\n\\请输入要查找的信息的教师课程:\"); gets(score); for(i=0;i printf(\"\\n\查找完毕,请按任意键返回!\"); getch(); fclose(fp1); return;//返回教师信息管理菜单 } /*************************************插入***************/ void addinfo(struct allteainfo *tea) { int i,count; char ch; if((fp1=fopen(\"student.dat\打开文件 打开方式为rb(只读) { printf(\"\\\Can not open file!\\n\"); getch(); exit(1); } rewind(fp1); //定位文件头开始 for(count=0;fread(&tea[count].teacher1,sizeof(struct teainfo),1,fp1)==1;count++) continue;//计算教师信息的教师总数 fclose(fp1); do { system(\"cls\"); printf(\"**************************************************************\\n\"); printf(\"\\请输入教师的姓名:\");gets(tea[count].teacher1.name);printf(\"\\n\"); printf(\"\\当前教师总数为%d\\n\ printf(\"\\请输入教师的职号:\");scanf(\"%d\ printf(\"\\请输入教师的C语言绩:\");scanf(\"%f\ printf(\"\\n\\n\"); count++;//增加一个教师信息 if((fp1=fopen(\"student.dat\重新打开文件更新 { printf(\"Can not open file!\\n\"); getch(); exit(1); } for(i=0;i 工成 for(count=0;fread(&tea[count].teacher1,sizeof(struct teainfo),1,fp1)==1;count++) continue;//计算教师信息的教师总数 system(\"cls\"); for(i=0;i rewind(fp1); //定位文件头开始 for(count=0;fread(&tea[count].teacher1,sizeof(struct teainfo),1,fp1)==1;count++) continue;//计算教师信息的教师总数 system(\"cls\"); printf(\"\\n\\n\\请输入要查找的信息的教师姓名:\"); for(i=0;i 因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- yrrf.cn 版权所有 赣ICP备2024042794号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务