You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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);
}