commit 60be76295c9146040f737575bc821068c734635f Author: m36890472 <1197374547@qq.com> Date: Sun Jan 13 21:00:19 2019 +0800 first diff --git a/课程设计源代码_学生选课系统_1807_18408000739_黄海臻.c.cpp b/课程设计源代码_学生选课系统_1807_18408000739_黄海臻.c.cpp new file mode 100644 index 0000000..9f1feec --- /dev/null +++ b/课程设计源代码_学生选课系统_1807_18408000739_黄海臻.c.cpp @@ -0,0 +1,227 @@ +#include +#include +#include +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); +}