C语言:驾驶员理论课程模拟考试与学习系统

打印 上一主题 下一主题

主题 1041|帖子 1041|积分 3123

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
一、课题内容和要求
  
驾驶员理论课程模拟考试与学习系统是在Dev C++编译情况下以C语言为编程语言编译完成的,为实现驾驶员科目一自主学习,查询知识和进行模拟考试的系统。同时为了方便驾校管理,到场了管理员模块,方便管理员对题库进行修改和编辑,同时,管理员可以为驾校员工添加新的管理员账户,普通用户可在注册后进入系统可进行自主练习,同时能在查看所有习题进行备考和进行错题重做。

  课题基本要求:
  (1)提供管理员和用户菜单选项,分别进入不同权限界面;
  (2)进入管理员界面需要暗码验证,管理员界面负责试题库的管理(修改、查询、删除、增长)以及考试结果的统计等;
  (3)进入用户界面需要输入用户 ID,界面菜单选项具有错题、学习和考试等功能;
  (4)用文件生存试题库并可随时增长试题到试题库中;
  (5)用户可实现输入自己的答案,系统可根据用户答案与尺度答案的对比实现判卷并给出结果。
   
  课题选做要求:
  (1)引进错题系统,可以进行错题重做。(已实现)
  (2)用户可查看所有题库并进行学习。(已实现)
  (3)用户、管理员ID均相对独立,不可重复,减少管理困难。(已实现)
  (4)拥有固定路径的资源库,方便后期对题库等内容进行优化和大面积的软件更新。(已实现)
   
  创新功能与特性:
  (1)用户每作答一题都会实时判定并给出实时分数,模拟真实考试场景。
  (2)管理员可以添加新的管理员。
  (3)参考微软等大型公司软件,界面在优化后更清楚整洁,全新的问候与提示语拉近用户距离感,提高用户使用体验。
   
  二、需求分析
  (1)提供可操纵的主菜单:输出菜单,用于显示以从文件中加载的总客户信息和若干个可选的功能选项。根据客户输入的选项来运行不同的功能,运行不同的函数。
  (2)用户主菜单和分菜单:用户主菜单提供注册和登录两个功能,适用于拥有和未拥有账号的用户进行相关操纵。用户分菜单是用户重要功能菜单,负责提供用户所需的模拟测试,错题学习,知识学习功能的引导并实现相应跳转。
  (3)管理员主菜单,分菜单以及题库菜单:管理员主菜单适用于管理员登录,仅在资源库文本文件 admin.txt 中存储的管理员才可以进行登录。管理员分菜单为管理员提供给相应的功能,包括对结果进行查看,添加新管理员,以及进入题库系统。题库菜单是题库系统的专用菜单,仅管理员才可以访问,它提供了对标题进行删除,增长,编辑等功能。
  三、概要设计
  

  • 重要存储布局
  1. typedef struct Admin               //管理员信息存储
  2. {
  3.        char ID[20];
  4.        char name[20];
  5.        char password[20];
  6. }Admin;
  7. Admin admin[N];
  8. typedef struct User                   //用户信息存储
  9.        char ID[20];
  10.        char name[20];
  11.        char password[20];
  12. }User;
  13. User user[N];
  14. typedef struct a               //试题的结构体
  15. {         
  16.        char text[M][N];       //存放试题
  17.        char answer[M];       //存放答案
  18. } text_answer;
  19. typedef struct userscore          //用户成绩的结构体
  20. {               
  21.        int userid;                         //存放用户ID
  22.        char username[20];           //存放用户名
  23.        int score;              //存放用户成绩
  24.        int mistakes[M];
  25. } SCORE;
  26. SCORE scores;
  27. typedef struct usermis            //用户成绩的结构体
  28. {
  29.        int userid;                         //存放用户ID
  30.        char username[20];           //存放用户名
  31.        int mistakes[M];               //存放用户错题题号
  32. } MISTAKE;
  33. MISTAKE MIS;
  34. 2.主要函数概要
  35. //系统菜单部分
  36. voidMainM();              //系统总菜单
  37. //用户菜单部分
  38. voidUserSM();             //用户主菜单(注册和登录)
  39. voidUserM();              //用户菜单(知识学习,测验,错题查看,错题重做)
  40. //管理员菜单部分
  41. voidAdminSM();           //管理员总菜单(登录,添加管理员)
  42. voidAdminM();            //管理员分菜单(题库,成绩管理)
  43. voidExerM();              //题库管理菜单(包含增加,删减,编辑)
  44. //用户函数
  45. int login();                           //用户登录(ID 密码)、
  46. void regist();                         //用户注册
  47. void product_random(int x, int a[]);       //题目随机生成
  48. void test(int pja);                      //考试模块函数
  49. void writescore(SCORE scores);          //分数写入
  50. void writemis(SCORE scores,int n);       //错题写入
  51. int Getmis(FILE *fp1,int a[]);            //错题文件读取
  52. int moveToNextLine(FILE *fp);          //文件内容扫描
  53. void Getmistakes(MISTAKE MIS);       //错题信息获取
  54. void mistest(int n,MISTAKE MIS);       //错题重做模块
  55. void studytest();                       //学习系统
  56. void savefile();                        //用户信息写入
  57. void readfile();                        //用户信息读取
  58. //管理员函数
  59. voidshowscore();                      //分数查看
  60. void addexe();                         //题目增加
  61. voidadminregist();                     //添加管理员
  62. voidadminsavefile();                   //管理员信息写入
  63. voidadminreadfile();                   //管理员信息读取
  64. voidadminlogin();                     //管理员登录
复制代码
四、源程序代码
  1. //maincontrol.c中的代码
  2. int main()
  3. {
  4.     MainM();
  5.     return 0;
  6. }
  7. //user.c中的代码
  8. int number=0;
  9. char passwd[20];
  10. void test(int pja)
  11. {
  12.     int i=0,j=0,k=0;
  13.     int flag,n=0,m;
  14.     text_answer a;
  15.     char ch1,ans;
  16.     char choice2;
  17.     FILE *fp,*fp1;
  18.     int random[560];
  19.     int mis=0,count=1,right=0,score=100;
  20.     if ((fp1=fopen("C:\\驾校系统资源库\\text.txt","r"))==NULL)
  21. { //判断文件是否打开成功
  22.         printf("嗯...试题库文件打开失败,请尝试联系管理员\n");
  23.         exit(0);
  24.     } else {
  25.         while((ch1=fgetc(fp1))!=EOF)
  26. {                                       //把题目放到数组中
  27.             if(ch1=='\n') {
  28.                 i++;
  29.                 j=0;
  30.             }
  31.             if(ch1 <= 0 || (ch1 >= '0' && ch1 <= '9') || (ch1 >= 'A' && ch1 <= 'Z') || ch1 == '.')
  32.                 //把题目放到数组中,题目里的汉字在计算机存的码值小于0
  33.             {
  34.                 a.text[i][j++]=ch1;
  35.             } else if(ch1>='a'&&ch1<='z')       //把答案存到数组中
  36.                 a.answer[k++]=ch1;
  37.         }
  38.         fclose(fp1);                         //关闭文件
  39.     }
  40.     i=560;
  41.     m=100;
  42.     product_random(i,random);                    //将随机数放到数组中
  43.     do {
  44.         flag=random[n++];                        //随机抽题
  45.         if((flag%5)!=0)。     //判断随机数是否为5的倍数(题目的行号为5的倍数)
  46.             m++;
  47.         else {
  48. Reanswer:
  49.             printf("%d.",count);
  50.             puts(a.text[flag+0]);
  51.             printf("\n");                        //输出题目和选项
  52.             puts(a.text[flag+1]);
  53.             printf("\n");
  54.             puts(a.text[flag+2]);
  55.             printf("                                               E.退出考试");
  56.             printf("\n");
  57.             puts(a.text[flag+3]);
  58.             printf("\n");
  59.             puts(a.text[flag+4]);
  60.             printf("\n");
  61.             printf("你选择:");
  62.             scanf("%c",&ans);
  63.             if (ans!='A'&&ans!='B'&&ans!='C'&&ans!='D'&&ans!='E')
  64. {                                                     //判断输入的选项
  65.                 printf("你的选择无效,请重新作答\n");
  66.                 system("pause");
  67.                 system("cls");
  68.                 fflush(stdin);
  69.                 goto Reanswer;
  70.             }
  71.             if (a.answer[flag/5]==ans+32) {                 //判断答案
  72.                 printf("\n选择正确\n\n");
  73.                 right++;
  74.             } else if(ans=='E') {
  75. Rechoose:
  76.                 system("cls");
  77.                 fflush(stdin);
  78.                 printf("是否确认退出考试?\n\n");
  79.                 printf("A.是              B.否\n\n");
  80.                 scanf("%c",&choice2);
  81.                 if (choice2!='A'&&choice2!='B')
  82. {                                                     //判断输入的选项
  83.                     printf("你的选择无效,我们无法进行相应操作,请重新选择\n");
  84.                     system("pause");
  85.                     system("cls");
  86.                     fflush(stdin);
  87.                
  88.                 goto Rechoose;}
  89.                 if(choice2=='A') {
  90.                     system("cls");
  91.                     fflush(stdin);
  92.                     break;
  93.                 }
  94.                 if(choice2=='B') {
  95.                 system("cls");
  96.                     fflush(stdin);
  97.                 goto  Reanswer;}
  98.             } else {
  99.                 printf("\n你的选择错误,正确答案为");
  100.                 printf("%c\n\n",a.answer[flag/5]-32);
  101.                 scores.mistakes[mis++]=flag/5;        //将错题行数放入数组
  102.             }
  103.             score=100-mis;
  104.             printf("剩余%d道题目         当前分数%d分\n\n",100-count,score);
  105. //输出剩余题目和当前分数
  106.             count++;
  107.             system("pause");
  108.             system("cls");
  109.             fflush(stdin);
  110.         }
  111.     } while(--m);
  112.     printf("你的考试已结束,您的总分为%d分\n",right);
  113.     scores.score=right;
  114.     scores.userid=((int)user[pja].ID[0]-48)*10000+((int)user[pja].ID[1]-48)*1000+((int)user[pja].ID[2]-48)*100+((int)user[pja].ID[3]-48)*10+((int)user[pja].ID[4]-48);
  115.     strcpy(scores.username,user[pja].name);
  116.     writescore(scores);
  117.     writemis(scores,mis);
  118.     system("pause");
  119.     printf("你的错题已经记录,你可以进入错题系统查看\n");
  120.     printf("即将为你返回菜单界面\n");
  121.     system("pause");
  122.     system("cls");
  123.     fflush(stdin);
  124.     UserM();
  125. }
  126. void product_random(int x, int a[])
  127. {                                                      //产生随机数并放进数组
  128.     srand(time(0));
  129.     int i, j, temp;
  130.     for(i = 0; i < x; i++) {
  131.         temp = rand() % x;
  132.         for(j = 0; j < i; j++) {
  133.             if(temp == *(a + j)) {
  134.                 i--;
  135.                 break;
  136.             } else
  137.                 *(a + i) = temp;
  138.         }
  139.     }
  140. }
  141. void writescore(SCORE scores) {
  142.     FILE *fp;
  143.     if((fp=fopen("C:\\驾校系统资源库\\userscore.txt","a+"))==NULL)
  144. {                                                    //判断文件是否打开成功
  145.         printf("很抱歉,打开成绩记录文件失败,请尝试创建相关文件以继续使用\n");
  146.         exit(0);
  147.     }
  148.     fprintf(fp,"%d|%s@%d",                           //将用户信息和成绩写入文本文件
  149.             scores.userid,
  150.             scores.username,
  151.             scores.score);
  152.     fputc('\n',fp);
  153.     fclose(fp);
  154. }
  155. void writemis(SCORE scores,int n) {
  156.     FILE *fp;
  157.     int i=0,j;
  158.     if((fp=fopen("C:\\驾校系统资源库\\mistakes.txt","a+"))==NULL)
  159. {
  160.         printf("很抱歉,打开错题记录文件失败,请尝试创建相关文件以继续使用\n");
  161.         exit(0);
  162.     }
  163.     fprintf(fp,"%d|%s@",                        //将用户信息和错题题号写入文本文件
  164.             scores.userid,
  165.             scores.username);
  166.     for(i=0; i<n; i++)  {
  167.         fprintf(fp,"%d,",scores.mistakes[i]);
  168.     }
  169.     fputc('\n',fp);
  170.     fclose(fp);
  171. }
  172. void studytest()
  173. {
  174.     int i=0,j=0,k=0;
  175.     int flag=0,n=0,m;
  176.     text_answer a;
  177.     char ch1,ans;
  178.     char choice2;
  179.     FILE *fp,*fp1;
  180.     int random[M];
  181.     int mis=0,count=1,right=0,score=100;
  182.    
  183.     if ((fp1=fopen("C:\\驾校系统资源库\\text.txt","r"))==NULL)
  184. {
  185.         printf("嗯...试题库文件打开失败,请尝试联系管理员");
  186.         exit(0);
  187.     } else {
  188.         while((ch1=fgetc(fp1))!=EOF) {            //把题目放到数组中
  189.             if(ch1=='\n') {
  190.                 i++;
  191.                 j=0;
  192.             }
  193.             if(ch1 <= 0 || (ch1 >= '0' && ch1 <= '9') || (ch1 >= 'A' && ch1 <= 'Z') || ch1 == '.')
  194.                 //把题目放到数组中,题目里的汉字在计算机存的码值小于0
  195.             {
  196.                 a.text[i][j++]=ch1;
  197.             } else if(ch1>='a'&&ch1<='z')           //把答案存到数组中
  198.                 a.answer[k++]=ch1;
  199.         }
  200.         fclose(fp1);
  201.     }
  202. while(1)
  203. {
  204. Reanswer:
  205.             printf("%d.",count);
  206.             puts(a.text[flag+0]);
  207.             printf("\n");                                     //输出题目和选项
  208.             puts(a.text[flag+1]);
  209.             printf("\n");
  210.             puts(a.text[flag+2]);
  211.             printf("                                               E.退出学习");
  212.             printf("\n");
  213.             puts(a.text[flag+3]);
  214.             printf("\n");
  215.             puts(a.text[flag+4]);
  216.             printf("\n");
  217.             printf("答案为:");
  218.             printf("%c\n\n",a.answer[flag/5]-32);
  219.             printf("A.上一题                     B.下一题\n\n");
  220.             scanf("%c",&ans);
  221.             if (ans!='A'&&ans!='B'&&ans!='E')
  222. {                                                         //判断输入的选项
  223.                 printf("你的选择无效,请重新选择。\n");
  224.                 system("pause");
  225.                 system("cls");
  226.                 fflush(stdin);
  227.                 goto Reanswer;
  228.             }
  229.             if (ans=='A') {
  230.                 if(flag==0)
  231.                 {printf("注意,这已经是第一题\n");
  232.                 system("pause");
  233.                 system("cls");
  234.                 fflush(stdin);
  235.                 goto Reanswer;
  236.                 }else
  237.                 {flag-=5;
  238.                 system("cls");
  239.                 fflush(stdin);
  240.                 count--;
  241.                 continue;
  242.                 }
  243.             }else if(ans=='B')
  244.             {if(flag==(k-1)*5)
  245.             {printf("注意,已经是最后一题\n");
  246.             system("pause");
  247.             system("cls");
  248.                 fflush(stdin);
  249.             goto Reanswer;
  250.             }
  251.             else
  252.             {flag+=5;
  253.             count++;
  254.             system("cls");
  255.             fflush(stdin);
  256.             continue;
  257.             }
  258.             }
  259.              else if(ans=='E') {
  260. Rechoose:
  261.                 system("cls");
  262.                 fflush(stdin);
  263.                 printf("是否确认退出学习?\n\n");
  264.                 printf("A.是              B.否\n\n");
  265.                 scanf("%c",&choice2);
  266.                 if (choice2!='A'&&choice2!='B') {
  267.                     printf("你的选择无效,请重新选择\n");
  268.                     system("pause");
  269.                     system("cls");
  270.                     fflush(stdin);
  271.                
  272.                 goto Rechoose;}
  273.                 if(choice2=='A') {
  274.                     system("cls");
  275.                     fflush(stdin);
  276.                     printf("知识学习已结束。\n");
  277.                     system("pause");
  278.                     system("cls");
  279.                     UserM();
  280.                     break;
  281.                 }
  282.                 if(choice2=='B') {
  283.                      system("cls");
  284.                     fflush(stdin);
  285.                 goto  Reanswer;
  286.                 }
  287.             } else {
  288.                 printf("\n选择错误,正确答案为");
  289.                 printf("%c\n\n",a.answer[flag/5]-32);
  290.                
  291.             }
  292.             flag+=5;
  293.     }
  294.     }
  295. void regist()
  296. {
  297.     int i,t;
  298.     int reg= 1;
  299.     char key[20];
  300.     char account[20];
  301.     char password[20];
  302.     printf("      ************************* 现在,让我们开始注册你的账户 *************************\n\n");
  303.     printf("      只需要几步简单的操作,你就可以开始使用我们的系统了!请按如下引导操作。\n");
  304.     printf("      请注意:你注册的ID必须为5位数字\n");
  305. a:  printf("      请输入ID:");
  306.     scanf("%s", account);
  307.     if (strspn(account, "0123456789") != strlen(account))
  308.     {
  309.     printf("      ★你输入的ID无效,请重新输入\n\a");
  310.         goto a;
  311.     }
  312.     if(strlen(account)!=5)
  313.     {
  314.     printf("      ★你输入的ID长度不合规,请重新输入:\n\a");
  315.         goto a;
  316.      }
  317.     for (i = 0; i < number; i++)
  318.     {
  319.         if (strcmp(user[i].ID, account) == 0)
  320.         {
  321.         printf("      ★这个账号已链接到其他账户,请重新输入\n\a");   
  322.             goto a;
  323.         }
  324.     }
  325.     printf("      请设置你的密码,请注意,您的密码仅限6位:  \n");
  326. b:    printf("      请输入密码:");
  327.     scanf("%s", password);
  328.         if(strlen(password)!=6)
  329.     {
  330.         printf("      ★你输入的密码长度不合规,请重新输入:\n\a");
  331.         goto b;
  332.      }
  333.      do
  334.     {
  335.         printf("      请再次输入您的密码:  ");
  336.         scanf("%s", &key);
  337.         if(strcmp(key,password) == 0)
  338.             t = 0;
  339.         else
  340.         {
  341.             t = 1;
  342.             printf("       两次输入的密码不一致,请重新输入 :) \n");
  343.         }
  344.     }while(t == 1);
  345.    
  346.     if (reg)
  347.     {
  348.         strcpy(user[number].ID, account);
  349.         strcpy(user[number].password, password);
  350.         printf("      请输入你的用户名: ");
  351.         scanf("%s",user[number].name);
  352.         number++;
  353.         printf("      搞定!\n");
  354.         printf("      你的账户已激活,现在可以开始使用你的系统了。\n") ;
  355.         system("pause");
  356.         system("cls");
  357.         fflush(stdin);
  358.     }
  359.     UserSM();
  360. }
  361. int login()
  362. {
  363.     int log = 0;
  364.     int i;
  365.     char account[20];
  366.     char password[20];
  367.     printf("\n       ************************* 如果你拥有我们的账户,请登录 *************************\n\n");
  368.    c: printf("       请输入账号:");
  369.     scanf("%s", account);
  370.       printf("       请输入密码:");
  371.     scanf("%s", password);
  372.     for (i = 0; i < number; i++)
  373.     {
  374.         if (strcmp(user[i].ID, account) == 0 && strcmp(user[i].password, password) == 0)
  375.         {
  376.         printf("       登录成功,即将进入系统\n");   
  377.             log = 1;
  378.             system("pause");
  379.             system("cls");
  380.             fflush(stdin);
  381.             UserM();
  382.             return i;
  383.         }
  384.     }
  385.     if(log==0)
  386.     {
  387.         printf("       你的用户名或者密码输入错误,请重新输入\n\a");
  388.     goto c;
  389.     }
  390.    return 0;
  391. }
  392. void savefile()
  393. {
  394.     int i = 0;
  395.     FILE *file;
  396.     fopen("C:\\驾校系统资源库\\user.txt", "w");
  397.     for (i = 0; i < number; i++)
  398.     {
  399.         fprintf(file, "%s %s %s\n", user[i].ID, user[i].password, user[i].name);
  400.     }
  401.     fclose(file);
  402. }
  403. void readfile()
  404. {
  405.     int i = 0;
  406.     FILE *file = fopen("C:\\驾校系统资源库\\user.txt", "r");
  407.     if (file)
  408.     {
  409.         while (1)
  410.         {
  411.             if (feof(file)) break;
  412.             i = number;
  413.             fscanf(file, "%s %s %s\n", user[i].ID, user[i].password, user[i].name);
  414.             number++;
  415.         }
  416.         fclose(file);
  417.     }
  418. }
  419. void Getmistakes(MISTAKE MIS) {
  420.     FILE *fp1;
  421.     char ch1,ch2,ch,id1,id2,id3,id4,id5;
  422.     int i=0,j,k,m,n,id,account;
  423.     int misid[1000]= {0};
  424.     int mistext[N];
  425.     if ((fp1=fopen("C:\\驾校系统资源库\\mistakes.txt","r+"))==NULL) { //判断文件是否打开成功
  426.         printf("很抱歉,打开错题记录文件失败,请尝试创建相关文件以继续使用\n\a");
  427.         exit(0);
  428.     }
  429.     while(ch != EOF) {.                                        //获取错题文件中的用户ID
  430.         ch = fgetc(fp1);
  431.         if (!i) {
  432.             id1 = ch;
  433.             id2 = fgetc(fp1);
  434.             id3 = fgetc(fp1);
  435.             id4 = fgetc(fp1);
  436.             id5 = fgetc(fp1);
  437.             id=((int)id1-48)*10000+((int)id2-48)*1000+((int)id3-48)*100+((int)id4-48)*10+(int)id5-48;
  438. //注意转换
  439.             misid[i++]=id;                                            //存放用户ID
  440.         }
  441.         if(ch=='\n') {
  442.             id1 =fgetc(fp1) ;
  443.             id2 = fgetc(fp1);
  444.             id3 = fgetc(fp1);
  445.             id4 = fgetc(fp1);
  446.             id5 = fgetc(fp1);
  447.             id=((int)id1-48)*10000+((int)id2-48)*1000+((int)id3-48)*100+((int)id4-48)*10+(int)id5-48;
  448. //注意转换
  449.             misid[i++]=id;                                            //存放用户ID
  450.         }
  451.     }
  452.     printf("请输入用户ID\n");
  453.     scanf("%d",&account);
  454.     system("cls");
  455.                 fflush(stdin);
  456.     MIS.userid=account;
  457.     for(j=0; j<i; j++) {
  458.         if(misid[j]==account) {
  459.             break;
  460.         }
  461.     }
  462.     rewind(fp1);                                                //使光标返回文件头
  463.     for(k=0; k<j; k++)
  464.         moveToNextLine(fp1);                                    //使光标向下移动一行
  465.     n=Getmis(fp1,mistext);
  466.     for(m=0; m<n; m++) {
  467.         MIS.mistakes[m]=mistext[m];
  468.     }
  469.     mistest(n,MIS);
  470.     fclose(fp1);                                                //关闭文件
  471. }
  472. int moveToNextLine(FILE *fp) {
  473.     int c;
  474.     if(fp == NULL) return -1;
  475.     while(1) {
  476.         c = fgetc(fp);
  477.         if(c == EOF) return EOF;
  478.         if(c == '\n') break;
  479.     }
  480.     return 0;
  481. }
  482. int Getmis(FILE *fp1,int a[]) {
  483.     char ch1,ch2,ch3,ch5,ch='a',id1,id2,id3,id4,id5;
  484.     int i=0,j,k,id,account,ch4;
  485.     while(ch1!= '\n') {
  486.         ch = fgetc(fp1);
  487.         while(ch=='@') {
  488.             ch1= fgetc(fp1);
  489.             if(ch1=='\n')
  490.                 break;
  491.             ch2=fgetc(fp1);
  492.             if(ch2!=',') {
  493.                 ch3=fgetc(fp1);
  494.                 if(ch3!=',') {
  495.                     ch4=((int)ch1-48)*100+((int)ch2-48)*10+(int)ch3-48;
  496.                     a[i++]=ch4;
  497.                     ch4=fgetc(fp1);
  498.                     continue;
  499.                 } else {
  500.                     ch4=((int)ch1-48)*10+(int)ch2-48;
  501.                     a[i++]=ch4;
  502.                     continue;
  503.                 }
  504.             } else {
  505.                 ch4=(int)ch1-48;
  506.                 a[i++]=ch4;
  507.                 continue;
  508.             }
  509.         }
  510.     }
  511.     return i;
  512. }
  513. void mistest(int n,MISTAKE MIS) {
  514.     int i=0,j=0,k=0,count2=0;
  515.     int flag,m;
  516.     text_answer a;
  517.     char ch1,ans;
  518.     char choice2;
  519.     FILE *fp,*fp1;
  520.     int random[M];
  521.     int mis=0,count=1,right=0,score=100;
  522.     if ((fp1=fopen("C:\\驾校系统资源库\\text.txt","r"))==NULL) {
  523.         printf("嗯...试题库文件打开失败,请尝试联系管理员");
  524.         exit(0);
  525.     } else {
  526.         while((ch1=fgetc(fp1))!=EOF) {
  527.             if(ch1=='\n') {
  528.                 i++;
  529.                 j=0;
  530.             }
  531.             if(ch1 <= 0 || (ch1 >= '0' && ch1 <= '9') || (ch1 >= 'A' && ch1 <= 'Z') || ch1 == '.')
  532.                 //把题目放到数组中,题目里的汉字在计算机存的码值小于0
  533.             {
  534.                 a.text[i][j++]=ch1;
  535.             } else if(ch1>='a'&&ch1<='z')
  536.                 a.answer[k++]=ch1;
  537.         }
  538.         fclose(fp1);
  539.     }
  540.     do {
  541.         flag=MIS.mistakes[count2++];//随机抽题
  542.         if((flag%1)!=0).                   //判断随机数是否为5的倍数(题目的行号为5的倍数)
  543.             n++;
  544.         else {
  545. Reanswer:
  546.             printf("%d.",count);
  547.             puts(a.text[flag*5+0]);
  548.             printf("\n");
  549.             puts(a.text[flag*5+1]);
  550.             printf("\n");
  551.             puts(a.text[flag*5+2]);
  552.             printf("                                               E.退出错题");
  553.             printf("\n");
  554.             puts(a.text[flag*5+3]);
  555.             printf("\n");
  556.             puts(a.text[flag*5+4]);
  557.             printf("\n");
  558.             printf("你选择:");
  559.             scanf("%c",&ans);
  560.             if (ans!='A'&&ans!='B'&&ans!='C'&&ans!='D'&&ans!='E') {
  561.                 printf("无效选择!请重新作答!\n");
  562.                 system("pause");
  563.                 system("cls");
  564.                 fflush(stdin);
  565.                 goto Reanswer;
  566.             }
  567.             if (a.answer[flag]==ans+32) {                         //判断答案
  568.                 printf("\n选择正确\n\n");
  569.                 right++;
  570.             } else if(ans=='E') {
  571. Rechoose:
  572.                 system("cls");
  573.                 fflush(stdin);
  574.                 printf("是否确认退出错题?\n\n");
  575.                 printf("A.是              B.否\n\n");
  576.                 scanf("%c",&choice2);
  577.                 if (choice2!='A'&&choice2!='B') { //判断输入的选项
  578.                     printf("无效选择!请重新选择!\n");
  579.                     system("pause");
  580.                     system("cls");
  581.                     fflush(stdin);
  582.                     goto Rechoose;
  583.                 }
  584.                 if(choice2=='A') {
  585.                     system("cls");
  586.                     fflush(stdin);
  587.                     break;
  588.                 }
  589.                 if(choice2=='B') {
  590.                     system("cls");
  591.                     fflush(stdin);
  592.                     goto  Reanswer;
  593.                 }
  594.             } else {
  595.                 printf("\n选择错误,正确答案为");
  596.                 printf("%c\n\n",a.answer[flag/5]-32);
  597.             }
  598.             score=100-mis;
  599.             count++;
  600.             system("pause");
  601.             system("cls");
  602.             fflush(stdin);
  603.         }
  604.     } while(--n);
  605.     printf("错题重做已结束,请继续学习,即将返回主界面。");
  606.     system("pause");
  607.     system("cls");
  608.     fflush(stdin);
  609.     UserM();
  610. }
  611. //admin.c中的代码
  612. int num=0;
  613. void showscore()
  614. {
  615.     FILE *fp;
  616.     char ch;
  617.     fp=fopen("C:\\驾校系统资源库\\userscore.txt", "r");
  618.     if (fp==0)
  619.         {
  620.         printf("抱歉,打开成绩记录文件失败,请尝试创建相关文件以继续使用");
  621.         exit(1);
  622.     }
  623.     printf("你的组织内的用户成绩如下:\n");
  624.     printf("提示:‘@’后是你组织成员的考试分数:\n");
  625.     printf("\n");
  626.     while ((ch=fgetc(fp))!=EOF)
  627.         {
  628.         putchar(ch);
  629.     }
  630. putchar('\n');
  631. fclose(fp);
  632. system("pause");
  633. system("cls");
  634. fflush(stdin);
  635. AdminM();
  636. }
  637. void addexe()。                                               //添加习题
  638. {
  639.     FILE *fp1;
  640.     char topic[N];
  641.     char choice1[N];
  642.     char choice2[N];
  643.     char choice3[N];
  644.     char choice4[N];
  645.     char answer;
  646.     int a;
  647.     if ((fp1=fopen("C:\\驾校系统资源库\\text.txt","a+"))==NULL) { /*判断文件是否打开成功*/
  648.         printf("嗯...试题库文件打开失败,请尝试联系管理员\n");
  649.         exit(0);
  650.     }
  651. do{
  652.     printf("请输入题目:\n\n");
  653.     gets(topic);printf("\n");
  654.     fprintf(fp1,"%s",topic);
  655.     fputc('\n',fp1);
  656.     fflush(stdin);
  657.     printf("请输入选项A:\n\n");
  658.     gets(choice1);printf("\n");
  659.     fprintf(fp1,"A、%s",choice1);
  660.     fputc('\n',fp1);
  661.     fflush(stdin);
  662.     printf("请输入选项B:\n\n");
  663.     gets(choice2);printf("\n");
  664.     fprintf(fp1,"B、%s",choice2);
  665.     fputc('\n',fp1);
  666.     fflush(stdin);
  667.     printf("请输入选项C:\n\n");
  668.     gets(choice3);printf("\n");
  669.     fprintf(fp1,"C、%s",choice3);
  670.     fputc('\n',fp1);
  671.     printf("请输入选项D:\n\n");
  672.     gets(choice4);printf("\n");
  673.     fflush(stdin);
  674.     fprintf(fp1,"D、%s",choice4);
  675. fflush(stdin);
  676. printf("请输入答案:\n\n");
  677. answer=getchar();printf("\n");
  678. fprintf(fp1,"%c",answer);
  679.     fputc('\n',fp1);
  680. fflush(stdin);
  681. printf("题目已成功添加!你是否需要继续添加题目?\n");
  682. printf("1 是   2 否\n");
  683. do{
  684.     scanf("%d",&a);
  685. } while(a!=1&&a!=2);
  686. if(a==1)
  687. {
  688.    
  689.     system("cls");
  690.     fflush(stdin);
  691.     continue;
  692. }
  693. if(a==2)
  694. {system("cls");
  695. fflush(stdin);
  696. printf("试题添加已结束。 \n") ;
  697. break;
  698. }
  699. }while(1);
  700. fclose(fp1);
  701. ExerM();
  702. }
  703. void adminregist()
  704. {
  705.     int i,t;
  706.     char key[20];
  707.     int reg= 1;
  708.     char account[20];
  709.     char password[20];
  710.     printf("       ************************* 现在,让我们开始添加管理员到你的组织 *************************\n");
  711.     printf("       只需要几步简单的操作,就可以成功添加新的管理员请按如下引导操作。\n");
  712.     printf("       请注意:你注册的ID必须为5位数字\n");
  713. a:  printf("       请输入你想要添加的管理员ID:");
  714.     scanf("%s", account);
  715.     if (strspn(account, "0123456789") != strlen(account))
  716.     {
  717.         printf("       ★你输入的ID无效,请重新输入\n");
  718.         goto a;
  719.     }
  720.     if(strlen(account)!=5)
  721.     {
  722.         printf("       ★你输入的ID长度不合规,请重新输入:\n");
  723.         goto a;
  724.      }
  725.     for (i = 0; i < num; i++)
  726.     {
  727.         if (strcmp(admin[i].ID, account) == 0)
  728.         {
  729.             printf("此管理员用户已存在,请尝试添加其他用户\n");   
  730.             goto a;
  731.         }
  732.     }
  733.     printf("       请输入您的密码,请注意,您的密码仅限6位:  \n");
  734. b:    printf("请输入密码:");
  735.     scanf("%s", password);
  736.         if(strlen(password)!=6)
  737.     {
  738.         printf("       ★你输入的密码长度不合规,请重新输入:\n");
  739.         goto b;
  740.      }
  741.      do
  742.     {
  743.         printf("       请再次输入您的密码:  ");
  744.         scanf("%s", &key);
  745.         if(strcmp(key,password) == 0)
  746.             t = 0;
  747.         else
  748.         {
  749.             t = 1;
  750.             printf("       两次输入的密码不一致,请重新输入 :) \n");
  751.         }
  752.     }while(t == 1);
  753.     if (reg)
  754.     {
  755.         strcpy(admin[num].ID, account);
  756.         strcpy(admin[num].password, password);
  757.         printf("       请输入你的用户名: ");
  758.         scanf("%s",admin[num].name);
  759.         num++;
  760.         printf("       搞定!\n");
  761.         printf("       管理员添加成功,现在可以开始管理系统了\n");
  762.         system("pause");
  763.         system("cls");
  764.         fflush(stdin);
  765.     }
  766.     AdminM();
  767. }
  768. void adminsavefile()
  769. {
  770.     int i = 0;
  771.     FILE *file = fopen("C:\\驾校系统资源库\\admin.txt", "w");
  772.     for (i = 0; i < num; i++)
  773.     {
  774.         fprintf(file, "%s %s %s\n", admin[i].ID, admin[i].password, admin[i].name);
  775.     }
  776.     fclose(file);
  777. }
  778. void adminreadfile()
  779. {
  780.     int i = 0;
  781.     FILE *file = fopen("C:\\驾校系统资源库\\admin.txt", "r");
  782.     if (file)
  783.     {
  784.         while (1)
  785.         {
  786.             if (feof(file)) break;
  787.             i = num;
  788.             fscanf(file, "%s %s %s\n", admin[i].ID, admin[i].password, admin[i].name);
  789.             num++;
  790.         }
  791.         fclose(file);
  792.     }
  793. }
  794. void adminlogin()
  795. {
  796.     int log = 0;
  797.     int i;
  798.     char account[20];
  799.     char password[20];
  800.     printf("\n       ************************* 如果你拥有管理员账户,请登录 *************************\n");
  801.    c: printf("       请输入账号:");
  802.     scanf("%s", account);
  803.       printf("       请输入密码:");
  804.     scanf("%s", password);
  805.     for (i = 0; i < num; i++)
  806.     {
  807.         if (strcmp(admin[i].ID, account) == 0 && strcmp(admin[i].password, password) == 0)
  808.         {
  809.         printf("       登录成功,即将进入系统\n");   
  810.             log = 1;
  811.             system("pause");
  812.             system("cls");
  813.             fflush(stdin);
  814.             AdminM();
  815.             
  816.         }
  817.     }
  818.     if(log==0)
  819.     {
  820.         printf("      你的用户名或者密码输入错误,请重新输入\n");
  821.     goto c;
  822.     }
  823. }
  824. //menu.c中的代码
  825. int cyn;
  826. //总菜单
  827. void MainM()
  828. {
  829.     int n;
  830.     printf("************ 欢迎使用 驾考通·驾驶员科目一模拟系统 ****************\n");
  831.     printf("*                                                                 *\n");
  832.     printf("*       1 管理员点这里            2 普通用户点这里                *\n");
  833.     printf("*                                                                 *\n");
  834.     printf("*                     0 退出程序                                  *\n");
  835.     printf("*                                                                 *\n");
  836.     printf("*******************************************************************\n");
  837.    
  838.     do {
  839.         scanf("%d",&n);
  840.     } while (n!=1&&n!=2&&n!=0);//读取用户输入的值,并进行相应跳转
  841.     switch (n)
  842.     {
  843.         case 1:
  844.             printf("正在进入管理员系统,请稍候...\n");
  845.             system("CLS");
  846.             AdminSM();  
  847.             break;
  848.         case 2:
  849.             printf("正在进入用户系统,请稍候...\n");
  850.             system("CLS");
  851.             UserSM();
  852.             break;
  853.         case 0:
  854.             printf("程序已退出!\n\a");
  855.             break;
  856.     }
  857. }
  858. //用户部分
  859. //用户主菜单
  860. void UserSM()
  861. {
  862.     int a;
  863.     printf("*************************  欢迎! *********************************\n");
  864.     printf("*                                                                 *\n");
  865.     printf("*       1 我已经拥有账号(登录)     2 没有账号?(注册一个!)   *\n");
  866.     printf("*                                                                 *\n");
  867.     printf("*                          0 返回                                 *\n");
  868.     printf("*                                                                 *\n");
  869.     printf("*******************************************************************\n");
  870.    
  871.     do {
  872.         scanf("%d",&a);
  873.     } while (a!=1&&a!=2&&a!=0);
  874.    
  875.     switch (a)
  876.     {
  877.         case 1:
  878.             system("cls");
  879.             fflush(stdin);
  880.             readfile();
  881.             cyn=login();//登录系统(已完成)
  882.             break;
  883.         case 2:
  884.             system("cls");
  885.             fflush(stdin);
  886.             readfile();
  887.             regist();
  888.             savefile();//注册系统(已完成)
  889.             break;
  890.         case 0:
  891.             system("cls");
  892.             fflush(stdin);
  893.             MainM();//返回主菜单(已完成)
  894.             
  895.     }
  896. }
  897. //用户分菜单
  898. void UserM()
  899. {
  900.     int a;
  901.     printf("**********************   祝你学习愉快   ************************\n");
  902.     printf("*                                                              *\n");
  903.     printf("*                  1 知识学习     2 模拟测试                   *\n");
  904.     printf("*                  3 错题重做                                  *\n");
  905.     printf("*                                                              *\n");
  906.     printf("*                          0 退出登录                          *\n");
  907.     printf("*                                                              *\n");
  908.     printf("****************************************************************\n");
  909.    
  910.     do {
  911.         scanf("%d",&a);
  912.     } while (a!=1&&a!=2&&a!=0&&a!=3&&a!=4);
  913.    
  914.     switch (a)
  915.     {
  916.         case 1:
  917.             system("cls");
  918.             fflush(stdin);
  919.             studytest(); //学习系统(已完成)
  920.             break;
  921.         case 2:
  922.             system("cls");
  923.             fflush(stdin);
  924.             test(cyn);//测验系统(已完成)
  925.             break;
  926.         case 3:
  927.             system("cls");
  928.             fflush(stdin);
  929.             Getmistakes(MIS);//错题重做
  930.             break;
  931.         case 0:
  932.             system("cls");
  933.             fflush(stdin);
  934.             UserSM();//返回用户主菜单(已完成)
  935.             break;
  936.             
  937.     }
  938. }
  939. //管理员部分
  940. //管理员主菜单
  941. void AdminSM()
  942. {
  943.     int a;
  944.     printf("*************************  欢迎! ****************************\n");
  945.     printf("*                                                            *\n");
  946.     printf("*                       1 管理员登录                         *\n");
  947.     printf("*                                                            *\n");
  948.     printf("*                       0 返回上一级                         *\n");
  949.     printf("*                                                            *\n");
  950.     printf("**************************************************************\n");
  951.    
  952.     do {
  953.         scanf("%d",&a);
  954.     } while (a!=1&&a!=0);
  955.    
  956.     switch (a)
  957.     {
  958.         case 1:
  959.             system("cls");
  960.             fflush(stdin);
  961.             adminreadfile();//管理员登录(已完成)
  962.             adminlogin();
  963.             break;
  964.         case 0:
  965.             system("cls");
  966.             fflush(stdin);
  967.             MainM();//返回总菜单 (已完成)
  968.             break;
  969.             
  970.     }
  971. }
  972. //管理员分菜单
  973. void AdminM()
  974. {
  975.     int a;
  976.     printf("********************  驾考通·后台管理系统   ********************\n");
  977.     printf("*                                                               *\n");
  978.     printf("*              1 题库管理            2 成绩查看                 *\n");
  979.     printf("*                       3 添加管理员                            *\n");
  980.     printf("*                       0 退出登录                              *\n");
  981.     printf("*                                                               *\n");
  982.     printf("*****************************************************************\n");
  983.    
  984.     do {
  985.         scanf("%d",&a);
  986.     } while (a!=1&&a!=2&&a!=0&&a!=3);
  987.    
  988.     switch (a)
  989.     {
  990.         case 1:
  991.             printf("请稍等,我们正在进入题库...");
  992.             printf("\n");
  993.             printf("\n");
  994.             printf("\n");
  995.             system("cls");
  996.             ExerM() ;//进入题库菜单(已完成)
  997.             break;
  998.         case 2:
  999.             system("cls");
  1000.             fflush(stdin);
  1001.             showscore(); //成绩查看(已完成)
  1002.             break;
  1003.         case 3:
  1004.             system("cls");
  1005.             fflush(stdin);
  1006.             adminreadfile();
  1007.             adminregist();
  1008.             adminsavefile();//添加管理员(已完成)
  1009.         case 0:
  1010.             system("cls");
  1011.             fflush(stdin);
  1012.             AdminSM();//返回管理员主菜单
  1013.             break;
  1014.             
  1015.     }
  1016. }
  1017. //题库管理菜单
  1018. void ExerM()
  1019. {
  1020.     int a;
  1021.     printf("*********************  驾考通·题库管理系统  ********************\n");
  1022.     printf("*                                                               *\n");
  1023.     printf("*                  1 增加试题     2 删除编辑试题                *\n");
  1024.     printf("*                  3 返回上页                                   *\n");
  1025.     printf("*                                                               *\n");
  1026.     printf("*                        0 退出登录                             *\n");
  1027.     printf("*                                                               *\n");
  1028.     printf("*****************************************************************\n");
  1029.    
  1030.     do {
  1031.         scanf("%d",&a);
  1032.     } while (a!=1&&a!=2&&a!=0&&a!=3&&a!=4);
  1033.     switch (a)
  1034.     {
  1035.         case 1://增加试题(已完成)
  1036.             system("cls");
  1037.             fflush(stdin);
  1038.             addexe();   
  1039.             break;
  1040.         case 2://删除编辑试题(已完成)
  1041.             system("cls");
  1042.             fflush(stdin);
  1043.             printf("题目编辑涉及错题系统变更\n");
  1044.             printf("请前往文件夹:桌面-驾校系统资源库-text.txt对该文本文件进行修改\n") ;
  1045.             system("pause");
  1046.             system("cls");
  1047.             fflush(stdin);
  1048.             ExerM();
  1049.             break;
  1050.         case 3:
  1051.             system("cls");
  1052.             fflush(stdin);
  1053.             AdminM();//返回管理员分菜单(已完成)
  1054.             break;
  1055.         case 0:
  1056.             system("cls");
  1057.             fflush(stdin);
  1058.             AdminSM();//返回管理员主菜单(已完成)
  1059.             break;
  1060.     }
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

卖不甜枣

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表