master
石皓华 6 years ago
parent 56101c8211
commit cf5395fa4b

@ -0,0 +1,267 @@
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
struct course//先定义两个结构体^_^,一个是课程信息,另外一个是学生选课的结构图。
{
int num;//课程编号
char name[20];//课程名称
char kind[10];//课程性质
int time;//总学时
int ttime;//授课学时
int etime;//实验上级学时
int mark;//学分
int term;//学期
};
struct student
{
int snum;//学号
int cnum;//课程编号
char cname[20];//课程名称
};
void insert()//课程信息录入
{
int mai_n();
FILE *fp;
struct course c;
int count;
int i;
if((fp=fopen("course.txt","a+"))==NULL)
{
printf("cannot open file\n");
}
printf("\n 请输入课程门数:\n");
scanf("%d",&count);
printf("课程编号 课程名称 课程性质(公共课/必修课) 总学时 授课学时 实验或上机学时 学分 开课学期(年份):\n");
for(i=0;i<count;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);
}
fclose(fp);
printf("已保存!");
system("pause");
system("cls");//清屏
mai_n();
}
void browser()//课程信息浏览
{
int mai_n();
FILE *fp;
struct course c;
int a;
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("\n1-返回菜单2-退出系统\n");
scanf("%d",&a);system("cls");//清屏
if(a==1)
mai_n();
else
exit(0);
}
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);
}
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);
}
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);
}
void mai_n()//主菜单
{
int n,w=0;
printf(" ********************************************************************************\n");
printf(" ** MENU **\n");
printf(" ********************************************************************************\n");
printf(" ** * @$ 1- 输 入 课 程 信 息^_^ * **\n");
printf(" ** * @$ 2- 浏 览 课 程 信 息^_^ * **\n");
printf(" ** * @$ 3- 查 询 课 程 信 息^_^ * **\n");
printf(" ** * @$ 4- 统 计 选 课 情 况^_^ * **\n");
printf(" ** * @$ 5- 进 入 选 课 操 作^_^ * **\n");
printf(" ** * @$ 0- 退 出 选 课 系 统^_^ * **\n");
printf(" ********************************************************************************\n");
printf(" 请选择1-5:");
scanf("%d",&n);
do
{
if(n>5||n<0)
{
printf("\n 输入错误!请重新输入!\n");
scanf("%d",&n);
}
else w=1;
}while(w==0);
switch(n)
{
case 1:insert();break;
case 2:browser();break;
case 3:search();break;
case 4:xuanke_information();break;
case 5:xuan_ke();break;
case 0:
printf("\n^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^\n\n 感谢您的使用~~~~~通信工程1803--制作人;石皓华&&王越。"),system("pause"),exit(0);
}
}
int main(void)//登录界面
{
int a,b,c=123,d=123;
printf("请输入本程序防盗安全账号密码登录系统(防盗安全账号、密码为123)\n"); //虽然没啥用
printf("账号;");
scanf("%d",&a);
printf("\n");
printf("密码;");
scanf("%d",&b);
printf("\n");
while(a!=c)
{
printf("账号错误!请重新输入!\n账号;");
scanf("%d",&a);
}
while(b!=d)
{
printf("密码错误!请重新输入!\n密码;");
scanf("%d",&b) ;
}
printf("登录成功^_^\n");
system("cls");//清屏
mai_n();//主菜单
return 0;
}
Loading…
Cancel
Save