学生选课管理系统源代码.docx
《学生选课管理系统源代码.docx》由会员分享,可在线阅读,更多相关《学生选课管理系统源代码.docx(9页珍藏版)》请在冰豆网上搜索。
学生选课管理系统源代码
#include
#include
#include
structcourse
{
intnum;
charname[20];
charkind[20];
intttime,mark,term;
}c;
structstudent
{
intsnum;
intcnum;
charcnam[20];
charsnam[20];
}s[500];
intcount;//全局变量
intmain()//主函数
{
intn;
intmenu();
intf1();
intluru();
intliulan();
intchaxun();
intxuanke();
inttongji();
printf("\n*********************************************");
printf("\n\n**********欢迎进入学生选课系统!
**********");
menu();
printf("\n");
printf("*******************theend*********************\n");
printf("\n*********************************************");
printf("\n\n请先选择1进行课程信息录入:
");
scanf("%d",&n);//防止错误,请重新输入
for(;n>5||n<0;)
{
printf("\n输入错误!
请重新输入!
\n");
scanf("%d",&n);
}
while(n>0&&n<6)
{
switch(n)
{
case1:
luru();break;//录入课程信息
case2:
liulan();break;//浏览课程信息
case3:
chaxun();break;//查询课程信息
case4:
xuanke();break;//进入选课操作
case5:
tongji();break;//统计选课情况
}
scanf("%d",&n);//选择所需操作
for(;n>5||n<0;)
{
printf("\n\n");
printf("\n输入错误!
请重新输入!
\n");
scanf("%d",&n);//防止错误,提示重新输入
}
system("cls");//清屏
}
if(n==0)
{
printf("\n\n\n\n\n\n\n");
printf("**********谢谢使用!
**********\n");
printf("\n\n\n\n\n");
}
exit(0);//退出选课系统
return0;
}
intmenu()//菜单函数
{
intn;
printf("\n\n\n\n");
printf("1.录入课程信息\n\n");
printf("2.浏览课程信息\n\n");
printf("3.查询课程信息\n\n");
printf("4.进入选课操作\n\n");
printf("5.统计选课情况\n\n");
printf("0.退出选课系统\n\n");
return0;
}
intf1()
{
printf("\n课程编号课程名称课程性质总学时学分开课学期:
\n");
return0;
}
intluru()//录入函数
{
FILE*fp;//定义指向文件的指针
structcoursec;
inti;
if((fp=fopen("D:
//course.txt","w"))==NULL)//建立文件"course.txt"
{
printf("cannotopenfile\n");
exit(0);
}
printf("\n请输入选择的课程门数:
");
scanf("%d",&count);
printf("\n\n");
f1();
for(i=0;i{
scanf("%d%s%s%d%d%d",&c.num,c.name,c.kind,&c.ttime,&c.mark,&c.term);
fprintf(fp,"%d\t%s\t%s\t%d\t%d\t%d\t",c.num,c.name,c.kind,c.ttime,c.mark,c.term);
}
fclose(fp);//关闭文件
printf("\n*********录入成功!
*********\n");
menu();
return0;
}
intliulan()//浏览函数
{
inti=0;
FILE*fp;//定义指向文件的指针
structcoursec;//定义课程结构体变量
if((fp=fopen("D:
//course.txt","r"))==NULL)//打开文件"course.txt"
{
printf("\ncannotopencourse!
\n");
exit(0);
}
f1();
while(!
feof(fp)&&i{fscanf(fp,"%d%s%s%d%d%d",&c.num,c.name,c.kind,&c.ttime,&c.mark,&c.term);
printf("%7d%11s%10s%9d%9d%8d\n",c.num,c.name,c.kind,c.ttime,c.mark,c.term);
i++;
}
fclose(fp);//关闭文件
menu();
return0;
}
intchaxun()//查询函数
{
FILE*fp;//定义指向文件的指针
structcoursec;//定义课程结构体变量
intscore;
intb,i=0;
charkind[20];
printf("\n1.按学分查询\n");
printf("\n2.按课程性质查询");
printf("请选择查询方式\n\n输入选项数字:
");
scanf("%d",&b);//防止错误,提示重新输入
for(;b<1||b>2;)
{
printf("\n输入错误!
请重新输入!
\n");
scanf("%d",&b);
}//按学分查询
if(b==1)
{
printf("\n输入你要查询的学分:
");
scanf("%d",&score);
if((fp=fopen("D:
//course.txt","r"))==NULL)
{
printf("\ncannotopencourse!
\n");
exit(0);
}
f1();
while(!
feof(fp)&&i{
fscanf(fp,"%d%s%s%d%d%d",&c.num,c.name,c.kind,&c.ttime,&c.mark,&c.term);
if(c.mark==score)//比较输入的分数和结构体中的分数,如果相同,输出那组数据
printf("%7d%11s%10s%9d%9d%8d\n",c.num,c.name,c.kind,c.ttime,c.mark,c.term);
i++;
}
}
elseif(b==2)//按课程性质查询
{
printf("\n\n输入你要查询的课程性质:
");
scanf("%s",kind);
if((fp=fopen("D:
//course.txt","r"))==NULL)//打开文件"course.txt"
{
printf("\ncannotopencourse!
\n");
}
f1();
while(!
feof(fp)&&i{
fscanf(fp,"%d%s%s%d%d%d",&c.num,c.name,c.kind,&c.ttime,&c.mark,&c.term);
if(strcmp(c.kind,kind)==0)//比较输入的字符串与原文件中的课程性质,如果相同,输出那组数据
printf("%7d%11s%10s%9d%9d%8d\n",c.num,c.name,c.kind,c.ttime,c.mark,c.term);
i++;
}
}
else
{
printf("输入错误!
");//选择错误,就退出
exit
(1);
}
fclose(fp);
menu();
return0;
}
intxuanke()//选课函数
{
intt=0,flag;
inti;
/*structcoursec;//定义课程结构体变量*/
FILE*fp;//定义指向文件的指针
do
{
printf("\n请输入学号姓名课程编号及课程名称:
");
scanf("%d%s%d%s",&s[t].snum,s[t].snam,&s[t].cnum,s[t].cnam);
if((fp=fopen("D:
//course.txt","r"))==NULL)//打开文件"course.txt"
{
printf("\ncannotopencourse!
\n");
exit(0);
}
while(!
feof(fp))//如果课程编号和课程名称与学生所选一致,就跳出,执行下一步
{
fscanf(fp,"%d%s%s%d%d%d",&c.num,c.name,c.kind,&c.ttime,&c.mark,&c.term);
if((s[t].cnum==c.num)&&(s[t].cnam==c.name))
t++;
break;
}fclose(fp);
printf("\n是否继续,是1,否0\n");
scanf("%d",&flag);
if((fp=fopen("D:
//student.txt","a+"))==NULL)//建立文件“student.txt”
{
printf("\ncannotopenstudent!
\n");
exit(0);
}//建立,并将学生选课信息输入"student.txt"
for(i=0;ifprintf(fp,"%d\t%s\t%d\t%s\t\n",s[t].snum,s[t].snam,s[t].cnum,s[t].cnam);
fclose(fp);//关闭选课文件"course.txt"
}while(flag);
printf("\n*********恭喜选课成功!
*********\n");
menu();
return0;
}
inttongji()//统计函数
{
inttotal=0;
intt,i=0;
FILE*fp;
if((fp=fopen("D:
//student.txt","r"))==NULL)//打开文件“student.txt”
{
printf("\ncannotopenstudent!
\n");
exit(0);
}
printf("\n学号姓名课程编号及课程名称\n");
while(!
feof(fp))//计数
{
fscanf(fp,"%d%s%d%s\n",&s[i].snum,s[i].snam,&s[i].cnum,s[i].cnam);//读取文件“student.txt”
total++;
i++;
}
t=i;
for(i=0;iprintf("%5d%6s%7d%10s\n",s[i].snum,s[i].snam,s[i].cnum,s[i].cnam);
printf("\n选课学生总人数为:
%d人",total);
fclose(fp);//关闭文件
menu();
return0;
}