|
|
#include<stdio.h>
|
|
|
#include<stdlib.h>
|
|
|
#include<string.h>
|
|
|
void menu();//定义系统菜单界面函数
|
|
|
void teacher_login();//老师登陆界面函数
|
|
|
void student_login();//学生登陆界面函数
|
|
|
void login();//登陆学生选课系统总界面
|
|
|
void out();//退出系统
|
|
|
void search();//课程查询
|
|
|
void look();//课程浏览
|
|
|
void select();//课程挑选
|
|
|
void put_course();//由老师首先输入课程的信息
|
|
|
struct course
|
|
|
{
|
|
|
int course_num;//课程编号
|
|
|
char course_name[10];//课程名字
|
|
|
char course_sore[10];//网上授课或教室授课
|
|
|
int course_score;//课程学分
|
|
|
int course_classtime;//授课学时
|
|
|
int course_programtime;//实验学时
|
|
|
int course_count;//课程已报人数
|
|
|
};
|
|
|
void out()
|
|
|
{
|
|
|
exit(0);
|
|
|
}//退出系统函数
|
|
|
void menu()//学生选课系统总界面
|
|
|
{
|
|
|
printf("********************************\n");
|
|
|
printf("欢迎来到湖南工业大学学生选课系统\n");
|
|
|
printf("********************************\n");
|
|
|
printf("按任意键进行\n");
|
|
|
getchar();
|
|
|
}
|
|
|
void login()//登陆界面
|
|
|
{
|
|
|
system("CLS");
|
|
|
void teacher_login();
|
|
|
void student_login();
|
|
|
int q;
|
|
|
do
|
|
|
{
|
|
|
printf("学生登陆请按:1\n");
|
|
|
printf("老师登陆请按:2\n");
|
|
|
printf("退出系统请按:3\n");
|
|
|
scanf("%d",&q);
|
|
|
if(q!=1&&q!=2&&q!=3)
|
|
|
{
|
|
|
printf("输入错误\n");
|
|
|
printf("请按任意键进行\n");
|
|
|
getchar();
|
|
|
getchar();
|
|
|
}
|
|
|
if(q==3)
|
|
|
out();//退出系统
|
|
|
switch(q)
|
|
|
{
|
|
|
case 1:student_login();break;
|
|
|
case 2:teacher_login();break;
|
|
|
}
|
|
|
}while(q!=1&&q!=2&&q!=3);
|
|
|
}
|
|
|
void teacher_login()//老师
|
|
|
{
|
|
|
system("CLS");
|
|
|
void search();
|
|
|
void look();
|
|
|
int e;
|
|
|
do
|
|
|
{
|
|
|
printf("课程查询请按:1\n");
|
|
|
printf("课程浏览请按:2\n");
|
|
|
printf("课程信息输入:3\n");
|
|
|
printf("退出请按:4\n");
|
|
|
scanf("%d",&e);
|
|
|
if(e!=1&&e!=2&&e!=3&&e!=4)
|
|
|
{
|
|
|
printf("输入错误\n");
|
|
|
printf("请按任意进行\n");
|
|
|
getchar();
|
|
|
getchar();
|
|
|
system("CLS");
|
|
|
}
|
|
|
else if(e==4)
|
|
|
out ();
|
|
|
else if(e==1||e==2)
|
|
|
{
|
|
|
switch(e)
|
|
|
{
|
|
|
case 1:search();break;
|
|
|
case 2:look();break;
|
|
|
}
|
|
|
}
|
|
|
else if(e==3)
|
|
|
put_course();
|
|
|
}while(e!=1&&e!=2&&e!=3&&e!=4);
|
|
|
}
|
|
|
void student_login()//学生
|
|
|
{
|
|
|
system("CLS");
|
|
|
void out();
|
|
|
void search();
|
|
|
void look();
|
|
|
void select();
|
|
|
int w;
|
|
|
do
|
|
|
{
|
|
|
printf("课程挑选请按:1\n");
|
|
|
printf("课程浏览请按:2\n");
|
|
|
printf("课程查询请按:3\n");
|
|
|
printf("退出请按:4\n");
|
|
|
scanf("%d",&w);
|
|
|
if(w!=1&&w!=2&&w!=3&&w!=4)
|
|
|
{
|
|
|
printf("输入数据错误\n");
|
|
|
printf("请按任意键进行\n");
|
|
|
getchar();
|
|
|
getchar();
|
|
|
system("CLS");
|
|
|
}
|
|
|
if(w==4)
|
|
|
exit(0);
|
|
|
switch(w)
|
|
|
{
|
|
|
case 1:select();break;
|
|
|
case 2:look();break;
|
|
|
case 3:search();break;
|
|
|
case 4:out();break;
|
|
|
}
|
|
|
}while(w!=1&&w!=2&&w!=3&&w!=4);
|
|
|
}
|
|
|
void select()//学生选课函数
|
|
|
{
|
|
|
system("CLS");
|
|
|
FILE *fp1;//储存课程的文件
|
|
|
int i=0,temp=0,n,j,r,t,y;
|
|
|
struct course courses[5];
|
|
|
if((fp1=fopen("course.txt","rb"))==NULL)//把存储课程的文件首地址赋给文件指针fp1
|
|
|
{
|
|
|
printf("文件打开错误\n");
|
|
|
printf("按任意键返回\n");
|
|
|
getchar();
|
|
|
getchar();
|
|
|
student_login();
|
|
|
}
|
|
|
do
|
|
|
{
|
|
|
fread(&courses[i],sizeof(struct course),1,fp1);//把文件的数据读到结构体中储存起来
|
|
|
i+=1;
|
|
|
}while(!feof(fp1));
|
|
|
fclose(fp1);
|
|
|
printf("输入你选择的课程编号:限1,2,3,4,5\n");//请输入1,2,3,4,5;
|
|
|
scanf("%d",&n);
|
|
|
for(j=0;j<5;j++)
|
|
|
if(n==courses[j].course_num)
|
|
|
{
|
|
|
temp+=1;
|
|
|
t=j;
|
|
|
break;
|
|
|
}
|
|
|
if(temp==0)
|
|
|
{
|
|
|
printf("不存在输入课程号对应的课程\n");
|
|
|
printf("如果继续进行请按1 返回请按2 \n");
|
|
|
scanf("%d",&r);
|
|
|
switch(r)
|
|
|
{
|
|
|
case 1:select();break;
|
|
|
case 2:student_login();break;
|
|
|
default:printf("输入错误,结束程序\n");exit(0);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
courses[t].course_count+=1;//进行学生选课的人数统计
|
|
|
printf("选课成功,请注意通知,按时参加课程!\n");
|
|
|
getchar();
|
|
|
getchar();
|
|
|
}
|
|
|
fp1=fopen("course.txt","wb");
|
|
|
for(y=0;y<5;y++)
|
|
|
{
|
|
|
fwrite(&courses[y],sizeof(struct course),1,fp1);//把学生选课情况录到文件中
|
|
|
}
|
|
|
fclose(fp1);
|
|
|
}
|
|
|
void look()//课程浏览函数 ,输出各个课程的信息
|
|
|
{
|
|
|
system("CLS");
|
|
|
struct course courses[5];
|
|
|
FILE *fp2;
|
|
|
int i=0,j;
|
|
|
if((fp2=fopen("course.txt","rb"))==NULL)
|
|
|
{
|
|
|
printf("文件打开错误\n");
|
|
|
printf("按任意键进行\n");
|
|
|
getchar();
|
|
|
exit(0);
|
|
|
}
|
|
|
do
|
|
|
{
|
|
|
fread(&courses[i],sizeof(struct course),1,fp2);
|
|
|
i+=1;
|
|
|
}while(!feof(fp2));
|
|
|
for(j=0;j<5;j++)
|
|
|
{
|
|
|
printf("课程编号:%d\n",courses[j].course_num);
|
|
|
printf("课程名字:%s\n",courses[j].course_name);
|
|
|
printf("课程类型:%s\n",courses[j].course_sore);
|
|
|
printf("课程学分:%d\n",courses[j].course_score);
|
|
|
printf("授课学时:%d\n",courses[j].course_classtime);
|
|
|
printf("实验学时:%d\n",courses[j].course_programtime);
|
|
|
printf("课程已报人数:%d\n\n",courses[j].course_count);
|
|
|
}
|
|
|
fclose(fp2);
|
|
|
getchar();
|
|
|
getchar();
|
|
|
}
|
|
|
void search()//课程查询函数
|
|
|
{
|
|
|
system("CLS");
|
|
|
FILE *fp3;
|
|
|
int num;
|
|
|
struct course courses[5];
|
|
|
int i=0,j;
|
|
|
printf("请输入需要查询的课程的编号:限1,2,3,4,5\n");//请输入1,2,3,4,5;
|
|
|
scanf("%d",&num);
|
|
|
system("CLS");
|
|
|
if(num!=1&&num!=2&&num!=3&&num!=4&&num!=5)
|
|
|
{
|
|
|
printf("输入错误!按任意键返回\n");
|
|
|
getchar();
|
|
|
getchar();
|
|
|
search();
|
|
|
}
|
|
|
if((fp3=fopen("course.txt","rb"))==NULL)
|
|
|
{
|
|
|
printf("文件打开错误\n");
|
|
|
printf("按任意键进行\n");
|
|
|
getchar();
|
|
|
exit(0);
|
|
|
}
|
|
|
do
|
|
|
{
|
|
|
fread(&courses[i],sizeof(struct course),1,fp3);
|
|
|
i+=1;
|
|
|
}while(!feof(fp3));
|
|
|
fclose(fp3);
|
|
|
for(j=0;j<5;j++)
|
|
|
if(courses[j].course_num==num)
|
|
|
{
|
|
|
printf("课程编号:%d\n",courses[j].course_num);
|
|
|
printf("课程名字:%s\n",courses[j].course_name);
|
|
|
printf("课程类型:%s\n",courses[j].course_sore);
|
|
|
printf("课程学分:%d\n",courses[j].course_score);
|
|
|
printf("授课学时:%d\n",courses[j].course_classtime);
|
|
|
printf("实验学时:%d\n",courses[j].course_programtime);
|
|
|
printf("课程已报人数:%d\n",courses[j].course_count);
|
|
|
break;
|
|
|
}
|
|
|
getchar();
|
|
|
getchar();
|
|
|
}
|
|
|
void put_course()
|
|
|
{
|
|
|
system("CLS");
|
|
|
FILE *fp;
|
|
|
struct course courses[5];
|
|
|
printf("老师向数据库文件输入五组课程数据。例如: \n");
|
|
|
printf("1 体适能 教室授课 5 30 3 0\n");
|
|
|
printf("2 英语 网上授课 5 30 5 0\n");
|
|
|
printf("3 湖南青马 网上授课 5 30 5 0\n");
|
|
|
printf("4 心理学 网上授课 5 30 5 0\n");
|
|
|
printf("5 心理健康 教室授课 5 30 5 0\n");
|
|
|
printf("有五次输入,注意每个成员间用空格隔开,刚输入时把已报人数设为0,输入一个结构体数组按回车键\n");
|
|
|
printf("数据依次代表:编号,名字,方式,学分,授课学时,实验学时,已报人数\n");
|
|
|
printf("老师测试时为节省时间可以把上面5组数据样例复制作为输入,在进行其他测试\n");
|
|
|
int j;
|
|
|
for(j=0;j<5;j++)
|
|
|
{
|
|
|
scanf("%d%s%s%d%d%d%d",&courses[j].course_num,courses[j].course_name,courses[j].course_sore,&courses[j].course_score,&courses[j].course_classtime,&courses[j].course_programtime,&courses[j].course_count);
|
|
|
}
|
|
|
int i;
|
|
|
if((fp=fopen("course.txt","wb"))==NULL)
|
|
|
{
|
|
|
printf("文件打开错误\n");
|
|
|
printf("按任意键进行\n");
|
|
|
getchar();
|
|
|
exit(0);
|
|
|
}
|
|
|
for(i=0;i<5;i++)
|
|
|
{
|
|
|
fwrite(&courses[i],sizeof(struct course),1,fp);
|
|
|
}
|
|
|
fclose(fp);
|
|
|
printf("课程信息输入成功\n");
|
|
|
getchar();
|
|
|
getchar();
|
|
|
}
|
|
|
int main()//主函数
|
|
|
{
|
|
|
menu();
|
|
|
printf("老师首次登陆时,点击老师选项,应输入课程信息,学生禁止点击\n");
|
|
|
system("pause");
|
|
|
login();
|
|
|
return 0;
|
|
|
}
|
|
|
|