From 93137c645414b7738828057b64e3342db584b6eb Mon Sep 17 00:00:00 2001 From: "18408000528@stu.hut.edu.cn" <18408000528@stu.hut.edu.cn> Date: Thu, 10 Jan 2019 21:37:25 +0800 Subject: [PATCH] curriculum design final --- 课程设计(final).cpp | 284 ++++++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 课程设计(final).cpp diff --git a/课程设计(final).cpp b/课程设计(final).cpp new file mode 100644 index 0000000..2e8ddad --- /dev/null +++ b/课程设计(final).cpp @@ -0,0 +1,284 @@ +#include +#include +#include +#include +#include +typedef struct exam_system //¶¨ÒåÁ´±í +{ + char problem[150]; + char answer[4][20]; + char right; + char input; + struct exam_system *next; +}EXAM; //ÀàÐÍÃû×Ô¶¨Òå + +void management(); //ÌâÄ¿¹ÜÀíº¯Êý +void add(); //Ìí¼ÓÌâÄ¿º¯Êý +void show(); //±éÀúÌâ¿âº¯Êý +void preservation(); //±£´æÎĵµº¯Êý +void change(); //ÐÞ¸ÄÌâÄ¿º¯Êý +void exam(); //¿¼ÊÔ³õʼ½çÃ溯Êý +void link(); //´´½¨Á´±íº¯Êý +void Answer(); //´ðÌ⺯Êý + +int sum; //ÌâÄ¿×ÜÊý +struct exam_system *p1,*p2,*head; +FILE *fp; + +int main() +{ + link(); + system("color 75"); //×Ô¶¨Òåbackground + exam(); + return 0; +} + +void link() //´´½¨Á´±í +{ + head=(EXAM *)malloc(sizeof(EXAM)); //´´½¨Í·½Úµã,²¢¸øÓèÒ»¸ö¶¯Ì¬ÄÚ´æ + p2=p1=head; //Á¬Ðø¸³Öµ + p1->next=NULL; //Áîp1Ö¸Ïòĩβ + if((fp=fopen("D:\\exam.txt","r+"))==NULL) + { + printf("Îļþ´ò¿ªÊ§°Ü£¡£¡"); + exit(0); + } + while(1) + { + p1=(EXAM*)malloc(sizeof(EXAM)); + if(fread(p1,sizeof(EXAM),1,fp)==0) //¶ÁÈ¡ÐÅÏ¢ + break; //·ñÔòÍ˳ö + p2->next=p1; //ÓëµÚÒ»¸ö½ÚµãÁ¬½Ó + p2=p1; //p1Óëp2ͬʱָÏòпª±ÙµÄ½Úµã + sum++; + p2->next=NULL; //Áíp2Ö¸Ïòĩβ + } + fclose(fp); +} + +void exam() //¿¼ÊÔ½çÃ溯Êý +{ + int x; + system("cls"); + printf("\t\t*********»¶Ó­À´µ½µ¥ÏîÑ¡ÔñÌ⿼ÊÔϵͳ*********\n"); + printf("\t\t* *\n"); + printf("\t\t* 1.ÌâÄ¿¹ÜÀí *\n"); + printf("\t\t* *\n"); + printf("\t\t* 2.¿ªÊ¼¿¼ÊÔ *\n"); + printf("\t\t* *\n"); + printf("\t\t* 3.Í˳ö *\n"); + printf("\t\t* *\n"); + printf("\t\t********************************************\n"); + printf("\n"); + printf("ÇëÑ¡Ôñ£º"); + scanf("%d",&x); + switch(x) + { + case 1:management();break; + case 2:Answer();break; + case 3:exit(0);break; + default :printf("ÊäÈëÓÐÎó£¡\n");break; + } +} + +void management() //ÌâÄ¿¹ÜÀíº¯Êý +{ + int x; + system("cls"); + printf("\t\t************»¶Ó­À´µ½ÌâÄ¿¹ÜÀíϵͳ************\n"); + printf("\t\t* *\n"); + printf("\t\t* 1.ÐÂÔöÌâÄ¿ *\n"); + printf("\t\t* *\n"); + printf("\t\t* 2.±éÀúÌâ¿â *\n"); + printf("\t\t* *\n"); + printf("\t\t* 3.ÐÞ¸ÄÌâÄ¿ *\n"); + printf("\t\t* *\n"); + printf("\t\t* 4.·µ»ØÉÏÒ»¼¶ *\n"); + printf("\t\t* *\n"); + printf("\t\t********************************************\n"); + printf("\n"); + printf("ÇëÑ¡Ôñ£º"); + scanf("%d",&x); + switch(x) + { + case 1:add();management();break; + case 2:show();management();break; + case 3:change();management();break; + case 4:;exam();break; + default :printf("ÊäÈëÓÐÎó£¡\n");break; + } +} + +void preservation() //±£´æÎĵµº¯Êý +{ + EXAM *current=NULL; + current=head->next; + fp=fopen("D:\\exam.txt","w+"); + do + { + fwrite(current,sizeof(EXAM),1,fp); //Öð¸ö´æ´¢ + current=current->next; //µ±Ç°Ö¸ÕëÖ¸ÏòÏÂÒ»¸ö + }while(current!=NULL); //Ö±µ½Ö¸Ïòĩβ + fclose(fp); + printf("\n±£´æ³É¹¦£¡£¡"); + getch(); +} + +void show() //±éÀúÌâ¿âº¯Êý +{ + int c,i; + EXAM *p=NULL; + system("cls"); + if(sum==0) + { + printf("Ìâ¿âÖÐûÓÐÌâÄ¿£¡\n"); + printf("°´ÈÎÒâ¼ü¼ÌÐø£¡"); + getch(); + } +else + { + p=head; + i=0; + do + { + p=p->next; + printf("%d.%s\n",i+1,p->problem); + c=0; + while(c<4) + { + printf("%c:",c+'A'); + printf("%s\n",p->answer[c++] ); + } + printf("ÕýÈ·´ð°¸:"); + printf("%c\n",p->right); + i=i+1; + printf("\n-------------------------------------------------------------\n"); + }while(p->next!=NULL); + p=NULL; + printf("°´ÈÎÒâ¼ü¼ÌÐø£¡\n"); + getch(); + } +} + +void add() //ÌâÄ¿Ìí¼Óº¯Êý +{ + int x,i; + system("cls"); + printf("\t\t**************»¶Ó­À´µ½ÌâÄ¿¹ÜÀíϵͳ****************\n"); + do + { + p1=(EXAM *)malloc(sizeof(EXAM)); + p2->next=p1; //ÏàÁ¬p1¡¢p2 + p2=p1; //Ö¸ÏòÏàͬ + printf("ÇëÊäÈëµÚ%d¸öÌâÄ¿£º",sum+1); + scanf("%s",p1->problem); + printf("ÇëÊäÈ뱸ѡ´ð°¸£º\n"); + for(i=0;i<4;i) + { + printf("%c)",i+'A'); + scanf("%s",p1->answer[i++] ); + } + printf("ÊäÈëÕýÈ·´ð°¸£º"); + p1->right =getchar(); + scanf("%c",&p1->right ); + sum+=1; + printf("\n"); + printf("\tÊÇ·ñ¼ÌÐøÌí¼Ó\n\t1.¼ÌÐø\n\t2.Í˳ö\nÇëÑ¡Ôñ£º"); + scanf("%d",&x); + if(x==2) + { + p2->next=NULL; + break; + } + system("cls"); + }while(x==1); + preservation(); +} + +void change() //ÐÞ¸ÄÌâÄ¿º¯Êý +{ + int i,num; + EXAM *p1=NULL; + EXAM *p2=NULL; + show(); + if(sum>=1) + { + p1=(EXAM *)malloc(sizeof(EXAM)); //ΪP1·ÖÅäÒ»¸ö¶¯Ì¬ÄÚ´æ + p2=head; + printf("ÇëÑ¡ÔñÐ޸ĵÄÌâÄ¿ÐòºÅ£º"); + scanf("%d",&num); + for(i=0;inext; + } //´Ëʱp2ÖÕÓÚÒÀ´ÎŲµ½num-1´¦ + printf("ÇëÊäÈëÌâÄ¿£º"); + scanf("%s",p1->problem); + printf("ÇëÊäÈ뱸ѡ´ð°¸£º\n"); + for(i=0;i<4;) + { + printf("%c:",i+'A'); + scanf("%s",p1->answer[i++] ); + } + printf("ÊäÈëÕýÈ·´ð°¸£º"); + p1->right=getchar(); + scanf("%c",&p1->right); + p1->next=p2->next->next; //´Ëʱнڵ㽫´úÌæÔ­½Úµã + p2->next=p1; //p1¡¢p2Á¬½Ó + p1=NULL; + p2=NULL; //×îºó¶¼ÖÃΪĩβ + preservation(); + } +} + +void Answer() //´ðÌ⺯Êý +{ + int i,j,c; + int n; + int score=0; + EXAM *p=NULL; + printf("×£Ä㿼ÊÔ˳Àû£¡£¡\n"); + system("cls"); + if(sum>0) + { + i=0; + p=head; + printf("ÇëÊäÈëÄãÐèÒªµÄÌâÁ¿£º"); + scanf("%d",&n); + do + { + p=p->next; //¸üÐÂÖ¸Õ룬Êä³öÏÂÒ»¸ö½á¹¹ÌåµÄÊý¾Ý + printf("%d.%s\n",i+1,p->problem); + c=0; + while(c<4) + { + printf("%c:",c+'A'); + printf("%s\n",p->answer[c++] ); + } + printf("ÇëÊäÈëÄãµÄ´ð°¸£º"); + p->input=getchar(); + scanf("%c",&p->input); + if(p->right==p->input) + { + printf("\n¹§Ï²£¡£¡ÄãµÄ´ð°¸ÊÇ %c £¬ÕýÈ·´ð°¸ÊÇ %c ",p->input,p->right); + score+=1; + } + else + { + printf("\nÌ«¿ÉϧÁË~ÄãµÄ´ð°¸ÊÇ %c £¬ÕýÈ·´ð°¸ÊÇ %c ",p->input,p->right); + } + i=i+1; + printf("\n----------------------------------------------------------\n"); + if(i==n) + break; + }while(p->next!=NULL); + printf("¿¼ÊÔ½áÊø!\n"); + printf("×ÜÌâÊý£º%d\nÕýÈ·Êý£º%d\n",n,score); + getch(); + ; + } + else + printf("Ìâ¿âÖÐûÓÐÌâÄ¿!\n"); + printf("°´ÈÎÒâ¼ü¼ÌÐø£¡\n"); + getchar(); +} +