diff --git a/2209040028/THE test of student b/2209040028/THE test of student new file mode 100644 index 0000000..8dd8390 --- /dev/null +++ b/2209040028/THE test of student @@ -0,0 +1,173 @@ +void add_question(QuestionBank L) + { + question* p = L, * n = newQuestion(); + int i; + printf("请输入问题:"); + scanf("%s", n->que); + for (i = 0; i < 4; ++i) + { + printf("请输入选项%c:", i + 'A'); + scanf("%s", n->options[i]); + } + while (getchar() != '\n'); + printf("请输入正确选项(A、B、C、D中的一个):"); + scanf("%c", &n->answer); + printf("请输入本题分数:"); + scanf("%f", &n->score); + while (p->next) p = p->next; + p->next = n; + printf("录入成功\n"); + } + +3.2修改试题模块 + + + void modify_question(QuestionBank L) + { + question* p = L->next; + int i = 0, choose; + while (p) + { + printf("%d. %s\n", i + 1, p->que); + p = p->next; + ++i; + } + printf("%d. 返回主菜单\n", i + 1); + printf("请输入序号,选择要修改的试题:"); + scanf("%d", &choose); + if (choose < 0 || choose >= i + 1) + { + if (choose != i + 1) + printf("输入错误,将返回主菜单\n"); + return; + } + else + { + int j; + p = L; + for (i = 0; p->next && i < choose; ++i) + p = p->next; + printf("请输入问题:"); + scanf("%s", p->que); + for (j = 0; j < 4; ++j) + { + printf("请输入选项%c:", j + 'A'); + scanf("%s", p->options[j]); + } + while (getchar() != '\n'); + printf("请输入正确选项(A、B、C、D中的一个):"); + scanf("%c", &p->answer); + printf("请输入本题分数:"); + scanf("%f", &p->score); + printf("修改成功\n"); + } +} + + +3.3抽取试题模块 + + + void extract_questions(QuestionBank L, QuestionBank TestPaper) + { + int N, n = 0; //N是总的抽题数,n是当前抽题数 + int num = 0; //当前题目总数 + printf("请输入要抽取的题目数量:"); + scanf("%d", &N); + question* p = L; + while (p) + { + ++num; + p = p->next; + } + if (N >= num) + { + printf("抽取题目数量大于当前已录入的题目数\n"); + return; + } + printf("试题抽取中,请耐心等待.....\n"); + while (n < N) + { + int i = 0, max_rand = 0; + question* p1 = L, * p2 = TestPaper; + srand(time(0) + i); + max_rand = rand() % num + 1; + while (i < max_rand) + { + p1 = p1->next; + ++i; + } + if (!is_repeat(TestPaper, p1)) + { + p1->nextQuestion = p2->nextQuestion; + p2->nextQuestion = p1; + ++n; + } + } + printf("试卷生成成功\n"); +} +界面展示: + + + + + +3.4答题模块 + +void answer_questions(QuestionBank TestPaper) +{ + question* p = TestPaper->nextQuestion; + if (!p) + printf("当前还未生成试卷\n"); + while (p) + { + char ans; + print_question(p); + while (getchar() != '\n'); + + scanf("%c", &ans); + if (ans == p->answer) + { + p->is_right = 1; + printf("恭喜答对\n"); + } + else + { + p->is_right = 0; + printf("很遗憾,答错了\n"); + } + p = p->nextQuestion; + } +} + +界面展示: + + +3.5评分模块 + +void give_score(QuestionBank TestPaper) +{ + int r = 0, w = 0; + float score_r = 0, score_w = 0; + question* p = TestPaper->nextQuestion; + if (!p) + { + printf("请先生成试卷后答题,最后再来评分!\n"); + return; + } + while (p) + { + if (p->is_right) + { + ++r; + score_r += p->score; + } + else + { + ++w; + score_w += p->score; + } + p = p->nextQuestion; + } + printf("本次共答了%d道题,其中答对%d道,答错%d道\n", r + w, r, w); + printf("总分:%.1f分,你的得分:%.1f分\n", score_r + score_w, score_r); +} diff --git a/2209040028/elective subject of study b/2209040028/elective subject of study new file mode 100644 index 0000000..90e4e99 --- /dev/null +++ b/2209040028/elective subject of study @@ -0,0 +1,304 @@ +#include +#include // 主流程图: +#include +typedef struct subjects +{ + int num; + char name[20]; + char kind[10]; + int stime; + int ttime; + int etime; + int score; + int term; + struct subjects *next; +}SUB; + +SUB *create_form() +{ + SUB *head,*tail,*p; + int num,stime,ttime; + int etime,score,term; + char name[20],kind[10]; + int size=sizeof(SUB); +head=tail=NULL; + + + +printf("输入选修课程信息:\n"); + scanf("%d %s %s %d %d %d %d %d",&num,&name,&kind,&stime,&ttime,&etime,&score,&term); + while(num!=0){ + p=(SUB *)malloc(size); + p->num=num; + strcpy(p->name,name); + strcpy(p->kind,kind); + p->stime=stime; + p->ttime=ttime; + p->etime=etime; + p->score=score; + p->term=term; + if(head==NULL) + head=p; + else + tail->next=p; + tail=p; + scanf("%d %s %s %d %d %d %d %d",&num,&name,&kind,&stime,&ttime,&etime,&score,&term); + } + tail->next=NULL; + return head; +} + +void savefile(SUB *head) +{ + SUB *p; + FILE *fp; + fp=fopen("subjects.txt","w"); + + + + + + + + + + + + + + +fprintf(fp,"课程编号 课程名称 课程性质 总学时 授课学时 实验或上机学时 学分 开课学期\n"); + for(p=head;p;p=p->next) + +fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",p->num,p->name,p->kind,p->stime,p->ttime,p->etime,p->score,p->term); + fclose(fp); +} + +void savefileadd(SUB *head) +{ + SUB *p; + FILE *fp; + fp=fopen("subjectsadd.txt","w"); + fprintf(fp,"课程编号 课程名称 课程性质 总学时 授课学时 实验或上机学时 学分 开课学期\n"); + for(p=head;p;p=p->next) + fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",p->num,p->name,p->kind,p->stime,p->ttime,p->etime,p->score,p->term); + fclose(fp); +} + +void savefiledel(SUB *head) +{ + SUB *p; + FILE *fp; + fp=fopen("subjectsdel.txt","w"); + fprintf(fp,"课程编号 课程名称 课程性质 总学时 授课学时 实验或上机学时 学分 开课学期\n"); + for(p=head;p;p=p->next) + fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",p->num,p->name,p->kind,p->stime,p->ttime,p->etime,p->score,p->term); + fclose(fp); +} + + + + + + + + +void prin(SUB *head) +{ + SUB *ptr; + if(head==NULL){ + printf("没有此门课程记录!\n"); + return; + } + printf("课程编号 课程名称 课程性质 总学时 授课学时 实践或上机学时 学分 开课学期\n"); + for(ptr=head;ptr;ptr=ptr->next) + printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term); +} + +void search(SUB *head) +{ + int a,num; + int t=1; + char type[10]; + char ch='a',ch1; + SUB *ptr; + + + + + + + +while(ch!=' '){ + printf("若要按课程性质查找请输入1,若要按学分查找请输入2:\n"); + scanf("%d",&a); + switch(a){ + case 1:printf("请输入要查找的课程的性质:\n"); + scanf("%s",type); + printf("课程编号 课程名称 课程性质 总学时 授课学时 实践或上机学时 学分 开课学期\n"); + for(ptr=head;ptr;ptr=ptr->next) + if(strcmp(type,ptr->kind)==0){ + + + + + +printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term); + t=0; + } + if(t) printf("未找到!\n"); + t=1; + break; + case 2:printf("输入要查找的课程的学分\n"); + scanf("%d",&num); + printf("课程编号 课程名称 课程性质 总学时 授课学时 实践或上机学时 学分 开课学期\n"); + for(ptr=head;ptr;ptr=ptr->next) + if(ptr->score==num){ + printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term); + t=0; + } + if(t) printf("未找到!\n"); + t=1; + + } +printf("继续查找请按回车键,结束请按空格键:\n"); + ch1=getchar(); //将回车键赋给CH1,否则CASE里面最后输入的回车键会赋给CH,因此用CH1填补。 + ch=getchar(); + } +} + +SUB *insert(SUB *head) +{ + SUB *ptr,*ptr2,*subj; + int size=sizeof(SUB); + char ch='a',ch1; + while(ch!=' '){ + subj=(SUB *)malloc(size); + ptr=subj; + printf("输入要插入的课程信息:\n"); + scanf("%d%s%s%d%d%d%d%d",&subj->num,subj->name,subj->kind,&subj->stime,&subj->ttime,&subj->etime,&subj->score,&subj->term); + + + +if(head==NULL){ + head=ptr; + head->next=NULL; + } + else{ + for(ptr2=head;ptr2;ptr2=ptr2->next) + if(ptr2->next==NULL){ + ptr2->next=subj; + subj->next=NULL; + break; + } + } + printf("继续插入请按回车,结束请按空格:\n"); + ch1=getchar(); //将回车键赋给CH1,否则subj->term输完后输入的回车键会赋给CH,因此用CH1填补。 + ch=getchar(); + } + return head; +} + +SUB *del(SUB *head) +{ + SUB *p1,*p2; + char ch='a',ch1; + int num; + while(ch!=' '){ + printf("输入想要删除的课程编号:\n"); + scanf("%d",&num); + if(head->num==num){ + p2=head; + head=head->next; + free(p2); + } + if(head==NULL) + return NULL; + p1=head; + p2=head->next; + + + + + + + +while(p2){ + if(p2->num==num){ + p1->next=p2->next; + free(p2); + } + else p1=p2; + p2=p1->next; + } + printf("继续删除请按回车,结束请按空格:\n"); + ch1=getchar(); //将回车键赋给CH1,否则num输完后再输入的回车键会赋给CH,因此用CH1填补。 + ch=getchar(); + } + return head; +} + +void choose(SUB *head) + + + + + + +{ + SUB *p,*q; + int a[5]; + int num,total=0,i=0,j; + printf("输入要选修的课程的编号,编号之间以空格分开,输完后以0结束\n"); +scanf("%d",&num); + while(num!=0){ + for(p=head;p;p=p->next) + if(p->num==num){ + total=total+p->score; + a[i]=num; + i++; + } + scanf("%d",&num); + } + if(total<60) printf("选修总学分未达到60,选修失败!\n"); + + + + +else { + printf("选修成功!\n"); + printf("您选修的课程为:\n"); + for(j=0;jnext) + if(q->num==a[j]) + + + + printf("%s ",q->name); + printf("\n"); +printf("***********************************\n"); +printf("***********************************\n"); +printf("***********************************\n"); +printf("***********************************\n"); + + } +} +void main() +{ + SUB *head=create_form(); + savefile(head); + prin(head); + search(head); + head=insert(head);//注意此处的必要性函数insert的的返回值重新赋给head! + savefileadd(head); + printf("修改后的信息为:\n"); + prin(head); + head=del(head); //注意此处的必要性,数del的的返回值重新赋给head! + savefiledel(head); + printf("修改后的课程信息为:\n"); + prin(head); + choose(head); + +} +