diff --git a/search.cpp b/search.cpp new file mode 100644 index 0000000..43bcac1 --- /dev/null +++ b/search.cpp @@ -0,0 +1,67 @@ +void search()//课程信息查询 +{ +int mai_n(); +FILE *fp; +struct course c; +int xuefen,time; +char kind[10]; +int a,b; +printf("1.按学分查询./ /2.按课程性质查询./ /3.按开课学期查询\n"); +printf("请选择查询方式,输入选项数字: "); +scanf("%d",&b); +if(b==1) +{ +printf("\n 请输入要查询的学分:\n"); +scanf("%d",&xuefen); +if((fp=fopen("course.txt","r"))==NULL) +{ +printf("\nCannot open course!\n"); +} +printf("课程编号 课程名称 课程性质 总学时 授课学时 实验或上机学时 学分 开课学期:\n"); +for(;!feof(fp);)//文件到结尾前运行 +{fscanf(fp,"%d%s%s%d%d%d%d%d\n",&c.num,&c.name,&c.kind,&c.time,&c.ttime,&c.etime,&c.mark,&c.term); +if(c.mark==xuefen) +printf("%5d%12s%9s%9d%9d%11d%11d%11d\n",c.num,c.name,c.kind,c.time,c.ttime,c.etime,c.mark,c.term); +} +} +else if(b==2){ +printf("\n 请输入要查询的课程性质:\n"); +scanf("%s",&kind); +if((fp=fopen("course.txt","r"))==NULL) +{ +printf("\nCannot open course!\n"); +} +printf("课程编号 课程名称 课程性质 总学时 授课学时 实验或上机学时 学分 开课学期:\n"); +for(;!feof(fp);) +{ +fscanf(fp,"%d%s%s%d%d%d%d%d\n",&c.num,&c.name,&c.kind,&c.time,&c.ttime,&c.etime,&c.mark,&c.term); +if(strcmp(c.kind,kind)==0) +printf("%5d%12s%9s%9d%9d%11d%11d%11d\n",c.num,c.name,c.kind,c.time,c.ttime,c.etime,c.mark,c.term); +} +} +else if(b==3){ +printf("\n 请输入要查询的课程开课学期;\n"); +scanf("%d",&time); +if((fp=fopen("course.txt","r"))==NULL) +{ +printf("\nCannot open course!\n"); +} +printf("课程编号 课程名称 课程性质 总学时 授课学时 实验或上机学时 学分 开课学期:\n"); +for(;!feof(fp);) +{fscanf(fp,"%d%s%s%d%d%d%d%d\n",&c.num,&c.name,&c.kind,&c.time,&c.ttime,&c.etime,&c.mark,&c.term); +if(c.term==time) +printf("%5d%12s%9s%9d%9d%11d%11d%11d\n",c.num,c.name,c.kind,c.time,c.ttime,c.etime,c.mark,c.term); +} +} +else{ +printf("输入错误!"); +exit(1); +} +fclose(fp); +printf("\n1-返回菜单;2-退出系统\n"); +scanf("%d",&a);system("cls");//清屏 +if(a==1) +mai_n(); +else +exit(0); +} diff --git a/xuan_ke.cpp b/xuan_ke.cpp new file mode 100644 index 0000000..26a9a27 --- /dev/null +++ b/xuan_ke.cpp @@ -0,0 +1,45 @@ +void xuan_ke()//学生选修课程 +{ +int mai_n(); +struct student s; +struct course c; +int a; +FILE *fp; +if((fp=fopen("course.txt","r"))==NULL)//文件没有内容报错 +{ +printf("\nCannot open course!\n"); +} +printf("课程编号 课程名称 课程性质 总学时 授课学时 实验或上机学时 学分开课学期:\n"); +for(;!feof(fp);) +{ +fscanf(fp,"%d %s %s %d %d %d %d %d\n",&c.num,&c.name,&c.kind,&c.time,&c.ttime,&c.etime,&c.mark,&c.term); +printf("%5d%12s%9s%9d%9d%11d%11d%11d\n",c.num,c.name,c.kind,c.time,c.ttime,c.etime,c.mark,c.term); +} +fclose(fp); +printf("*@********#*******************************&****^**^*****&********************************#*****@**\n"); +printf("\n 请输入您的学号 及 您要选择的课程编号:\n"); +scanf("%d%d",&s.snum,&s.cnum); +if((fp=fopen("course.txt","r"))==NULL) +{ +printf("\nCannot open course!\n"); +} +for(;!feof(fp);) +{ +fscanf(fp,"%d %s %s %d %d %d %d %d\n",&c.num,&c.name,&c.kind,&c.time,&c.ttime,&c.etime,&c.mark,&c.term); +if(s.cnum==c.num) +break; +} +fclose(fp); +if((fp=fopen("student.txt","a+"))==NULL) +{ +printf("\nCannot open student!\n"); +} +fprintf(fp,"%d %d %s\n",s.snum,s.cnum,c.name); +fclose(fp); +printf("\n1-返回菜单;2-退出系统\n"); +scanf("%d",&a);system("cls");//清屏 +if(a==1) +mai_n(); +else +exit(0); +} diff --git a/xuanke_information.cpp b/xuanke_information.cpp new file mode 100644 index 0000000..a6802c8 --- /dev/null +++ b/xuanke_information.cpp @@ -0,0 +1,26 @@ +void xuanke_information()//统计选课情况 +{ +int mai_n(); +int total=0; +int a; +FILE *fp; +struct student s; +if((fp=fopen("student.txt","r"))==NULL)//文件没有内容报错 +{ +printf("\nCannot open student!\n"); +} +printf(" 学号 课程编号 课程名称\n"); +for(;!feof(fp);) +{fscanf(fp,"%d%d%s\n",&s.snum,&s.cnum,&s.cname); +total++; +printf("%7d%9d%13s\n",s.snum,s.cnum,s.cname); +} +printf("\n 选课学生总人数为:%d 人",total); +fclose(fp); +printf("\n1-返回菜单;2-退出系统\n"); +scanf("%d",&a);system("cls");//清屏 +if(a==1) +mai_n(); +else +exit(0); +}