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.
holrk/学生选修课程系统.cpp

193 lines
5.0 KiB

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct course
{
char name[100];
char kind[30];
int num;
int time;
int ttime;
int etime;
int mark;
int term;
};
struct student
{
char snum[11];
int cnum;
char cname[100];
};
void insert() /*输入信息*/
{ int main();
FILE *fp;
struct course c;
int secret=112112;
int secret1;
int n;
system("cls");
if((fp=fopen("course.txt","a+"))==NULL)
{printf("cannot open course\n");}
printf("请输入密码:");
scanf("%d",&secret1);
if(secret1==secret)
{
printf("密码输入正确,请输入课程门数:");
scanf("%d",&n);
printf("课程编号 课程名称 课程性质 总学时 授课学时 实验学时 学分 开课学期:\n");
for(int i=1;i<=n;i++)
{
scanf("%d %s %s %d %d %d %d %d",&c.num,&c.name,&c.kind,&c.time,&c.ttime,&c.etime,&c.mark,&c.term);
fprintf(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);
}
}
else
printf("你输入的密码有误,请重试");
fclose(fp);
main();
}
void browser() /*信息浏览*/
{ int main();
FILE *fp;
struct course c;
system("cls");
if((fp=fopen("course.txt","r"))==NULL)
{printf("cannot open course\n");}
printf("课程编号 课程名称 课程性质 总学时 授课学时 实验学时 学分 开课学期:\n");
for(;!feof(fp);)
{
fscanf(fp,"%d%s%s%d%d%d%d%d",&c.num,&c.name,&c.kind,&c.time,&c.ttime,&c.etime,&c.mark,&c.term);
printf("%5d%12s%9s%9d%9d%11d%7d%7d\n",c.num,c.name,c.kind,c.time,c.ttime,c.etime,c.mark,c.term);
}
fclose(fp);
main();
}
void search() /*信息查询*/
{ int main();
FILE *fp;
struct course c;
int score,b;
system("cls");
loop:
printf("1.按学分查询 2.按课程性质查询\n");
printf("请选择查询方式,输入选项数字:");
scanf("%d",&b);
if(b==1)
{
printf("请输入您要查询的学分:");
scanf("%d",&score);
if((fp=fopen("course.txt","r"))==NULL)
{
printf("cannot open course!\n");
}
else
printf("课程编号 课程名称 课程性质 总学时 授课学时 实验或上机学时 学分 开课学期:\n");
for(;!feof(fp);)
{
fscanf(fp,"%d%s%s%d%d%d%d%d",&c.num,&c.name,&c.kind,&c.time,&c.ttime,&c.etime,&c.mark,&c.term);
if(score==c.mark)
printf("%5d%12s%9s%9d%9d%11d%7d%7d\n",c.num,c.name,c.kind,c.time,c.ttime,c.etime,c.mark,c.term);
}
}
else if(b==2)
{
char kind1[10];
system("cls");
printf("请输入您要查询的课程性质:");
scanf("%s",&kind1);
if((fp=fopen("course.txt","r"))==NULL)
{
printf("cannot open course!\n");
}
else
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,kind1)==0)
printf("%5d%12s%9s%9d%9d%11d%10d%10d\n",c.num,c.name,c.kind,c.time,c.ttime,c.etime,c.mark,c.term);
}
}
else
{ printf("输入有误\n"); goto loop;}
fclose(fp);
main();
}
void xuankeinformation() /*学生选课情况*/
{ int main();
FILE *fp;
struct student s;
system("cls");
if((fp=fopen("student.txt","r"))==NULL)
{
printf("cannot open course!\n");
}
printf(" 学号 课程编号 课程名称 \n");
for(;!feof(fp);)
{
fscanf(fp,"%s %d %s",&s.snum,&s.cnum,&s.cname);
printf("%7s %5d %17s\n",s.snum,s.cnum,s.cname);
}
fclose(fp);
main();
}
void xuanke() /*学生进行选课*/
{
int main();
FILE *fp;
struct student s;
struct course c;
system("cls");
printf("请输入你的学号以及想选的课程的编号\n");
scanf("%s %d",&s.snum,&s.cnum);
if((fp=fopen("course.txt","r"))==NULL)
{
printf("cannot 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(c.num==s.cnum)
break;
}
fclose(fp);
if((fp=fopen("student.txt","a+"))==NULL)
{
printf("cannot open student!\n");
}
fprintf(fp,"%s %d %s\n",s.snum,s.cnum,c.name);
fclose(fp);
main();
}
int main()
{
loop:
printf("\n\n");
printf(" 学生选修课程系统 \n\n\n");
printf(" ******** 1.课程信息录入 ******** \n");
printf(" ******** 2.课程信息浏览 ******** \n");
printf(" ******** 3.课程信息查询 ******** \n");
printf(" ******** 4.学生选修课程统计 ******** \n");
printf(" ******** 5.选课 ******** \n");
printf(" ******** 0.退出 ******** \n");
printf("请输入你想选择的数字\n");
int x;
scanf("%d",&x);
switch(x)
{
case 1:insert();break;
case 2:browser(); break;
case 3:search(); break;
case 4:xuankeinformation(); break;
case 5:xuanke(); break;
case 0:exit(0);break;
default:printf("你的选择有错误!"); goto loop;
}
return 0;
}