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.
xsxkxt/课程设计源代码_学生选课系统_1807_1840800...

228 lines
4.5 KiB

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct subject_info
{
int number;
char name[20];
int score;
int time;
int classtime;
int exprimenttime;
char term[10];
} subject;
typedef struct student_info
{
char xh[4];
char name[10];
int subject_num1;
int subject_num2;
} student;
subject sub;
student stu;
void infoinput() //课程信息录入函数
{
FILE *fp;
fp=fopen("si.txt","a+");
if(fp==NULL)
{
printf("文件打开失败!\n");
exit(0);
}
printf("请输入课程编号;\n");
scanf("%d",&sub.number);
printf("请输入课程名称;\n");
scanf("%s",sub.name);
printf("请输入课程学分;\n");
scanf("%d",&sub.score);
printf("请输入课程学时;\n");
scanf("%d",&sub.time);
printf("请输入授课学时;\n");
scanf("%d",&sub.classtime);
printf("请输入实验学时;\n");
scanf("%d",&sub.exprimenttime);
printf("请输入开课学期;\n");
scanf("%s",sub.term);
fprintf(fp,"\n%d\t%s\t%d\t%d\t%d\t%d\t%s\t\n",sub.number,sub.name,sub.score,sub.time,sub.classtime,sub.exprimenttime,sub.term);
if(fclose(fp))
{
printf("无法关闭文件!\n");
exit(0);
}
}
void studentinfo() //学生选课信息录入
{
FILE *fp;
fp=fopen("student.txt","a+");
if(fp==NULL)
{
printf("文件打开失败!");
exit(0);
}
printf("请输入学生学号:");
scanf("%s",stu.xh);
printf("请输入学生姓名:");
scanf("%s",stu.name);
printf("请输入您选的第一门课程的编号:");
scanf("%d",&stu.subject_num1);
printf("请输入您选的第二门课程的编号:");
scanf("%d",&stu.subject_num2);
fprintf(fp,"\n%s\t%s\t%d\t%d\t\n",stu.xh,stu.name,stu.subject_num1,stu.subject_num2);
if(fclose(fp))
{
printf("无法关闭文件!");
exit(0);
}
}
void lookthrough() //课程信息浏览
{
FILE *fp;
fp=fopen("si.txt","r");
if(fp==NULL)
{
printf("文件打开失败!");
exit(0);
}
rewind(fp);
printf("选修课程信息一览表\n");
printf("编号\t名称\t学分\t学时\t授课学时\t实验学时\t开课学期\n");
while(!feof(fp))
{
fscanf(fp,"%d\t%s\t%d\t%d\t%d\t%d\t%s\t",&sub.number,sub.name,&sub.score,&sub.time,&sub.classtime,&sub.exprimenttime,sub.term);
printf("\n%d\t%s\t%d\t%d\t%d\t %d\t %s\t\n",sub.number,sub.name,sub.score,sub.time,sub.classtime,sub.exprimenttime,sub.term);
}
if(fclose(fp))
{
printf("无法关闭文件!\n");
exit(0);
}
}
void xh_cx() //按学号查询
{char s[4];
char a[4]="";
FILE *fp;
int flag=0;
printf("请输入查询的学号:");
scanf("%s",s);
fp=fopen("student.txt","r");
if(fp==NULL)
{
printf("文件打开失败!");
exit(1);
}
rewind(fp);
while(!feof(fp))
{
fscanf(fp,"%s%s%d%d",stu.xh,stu.name,&stu.subject_num1,&stu.subject_num2);
strncpy(a,stu.xh,4);
if(strcmp(a,s)==0)
{
printf("%s\t%s\t%d\t%d\n",stu.xh,stu.name,stu.subject_num1,stu.subject_num2);
flag=1;
}
}
if(flag==0)
printf("Not Found!\n");
if(fclose(fp))
{
printf("无法关闭文件!");
exit(0);
}
}
void score_cx() //按学分查询
{
FILE *fp;
int xf,a;int flag=0;
fp=fopen("si.txt","r");
if(fp==NULL)
{
printf("文件打开失败!");
exit(1);
}
rewind(fp);
printf("请输入学分:");
scanf("%d",&xf);
while(!feof(fp))
{
fscanf(fp,"%d\t%s\t%d\t%d\t%d\t%d\t%s\t",&sub.number,sub.name,&sub.score,&sub.time,&sub.classtime,&sub.exprimenttime,sub.term);
a=sub.score;
if(xf==a)
{
printf("%d\t%s\t%d\t%d\t%d\t%d\t%s\t\n",sub.number,sub.name,sub.score,sub.time,sub.classtime,sub.exprimenttime,sub.term);
flag=1;
}
}
if(flag==0)
printf("Not Found!\n");
if(fclose(fp))
{
printf("无法关闭文件!");
exit(0);
}
}
int main()
{
int n;
do
{
printf("\n学生选课系统\n\n");
printf("------------------\n");
printf("| 1.课程信息录入 |\n");
printf("| 2.选课信息录入 |\n");
printf("| 3.课程信息浏览 |\n");
printf("| 4.按学号查询 |\n");
printf("| 5.按学分查询 |\n");
printf("| 6.退出 |\n");
printf("------------------\n\n");
printf("请输入服务选项:");
scanf("%d",&n);
switch(n)
{
case 1:
{
system("cls");
infoinput();
break;
}
case 2:
{
system("cls");
studentinfo();
break;
}
case 3:
{
system("cls");
lookthrough();
break;
}
case 4:
{
system("cls");
xh_cx();
break;
}
case 5:
{
system("cls");
score_cx();
break;
}
case 6:
{
system("cls");
printf("欢迎使用本系统。谢谢!");
}
default:break;
}
} while(n!=6);
}