小型考试系统

源代码:

  1 #include <stdio.h>
  2 #include <string.h>
  3 #include <stdlib.h>
  4 
  5 #define   Score_Num  35
  6 
  7 struct Standard
  8 {
  9     int A;
 10     int B;
 11     int C;
 12     int D;
 13     char Correct_Answer;
 14 };
 15 
 16 struct Standard Standard_Answer[Score_Num];//记录标准答案
 17 
 18 struct Stu
 19 {
 20     int Num;//学生学号
 21     char Name[32];//学生姓名
 22     char Answer[Score_Num];//准确答案
 23     int Score;//学生分数
 24 };
 25 
 26 struct Stu Student[100];//存储学生信息
 27 int Stu_Num = 0;//存储学生数目
 28 
 29 //---------------------------------统计标准答案------------------------
 30 void Standard_Num()
 31 {
 32     int i, j;
 33     int tag;
 34     for(i=0;i<Stu_Num;i++)
 35     {
 36         for(j=0; j<Score_Num; j++)
 37         {
 38             switch(Student[i].Answer[j])
 39             {
 40             case 'A':Standard_Answer[j].A++;break;
 41             case 'B':Standard_Answer[j].B++;break;
 42             case 'C':Standard_Answer[j].C++;break;
 43             case 'D':Standard_Answer[j].D++;break;
 44             }
 45         }
 46     }
 47     for(j=0; j<Score_Num; j++)
 48     {
 49         tag = Standard_Answer[j].A;
 50         Standard_Answer[j].Correct_Answer = 'A';
 51         if(Standard_Answer[j].B > tag)
 52         {
 53             tag = Standard_Answer[j].B;
 54             Standard_Answer[j].Correct_Answer = 'B';
 55         }
 56         if(Standard_Answer[j].C > tag)
 57         {
 58             tag = Standard_Answer[j].C;
 59             Standard_Answer[j].Correct_Answer = 'C';
 60         }if(Standard_Answer[j].D > tag)
 61         {
 62             tag = Standard_Answer[j].D;
 63             Standard_Answer[j].Correct_Answer = 'D';
 64         }
 65     }
 66 }
 67 //---------------------------------统计标准答案------------------------
 68 
 69 
 70 
 71 //------------------实现每次从文本文件中读取一行-----------------------
 72 char* Read_line(FILE* f, char* line)
 73 {
 74     
 75     return line;
 76 }
 77 //------------------实现每次从文本文件中读取一行-----------------------
 78 
 79 //------------------打印标准答案---------------------------------------
 80 void Standard_Print()
 81 {
 82     int i;
 83     for(i=0; i<Score_Num; i++)
 84     {
 85         printf("第%d题标准答案:%c    选A的人数%d,选B的人数%d,选C的人数%d,选D的人数%d,\n", i+1, Standard_Answer[i].Correct_Answer, Standard_Answer[i].A, Standard_Answer[i].B, Standard_Answer[i].C, Standard_Answer[i].D);
 86     }
 87 }
 88 //------------------打印标准答案---------------------------------------
 89 
 90 //------------------计算每个学生的成绩---------------------------------
 91 void Student_Score_Get()
 92 {
 93     int i, j;
 94     for(i=0;i<Stu_Num;i++)
 95     {
 96         Student[i].Score = 0;
 97         for(j=0; j<15; j++)
 98         {
 99             if(Student[i].Answer[j] == Standard_Answer[j].Correct_Answer)
100             Student[i].Score = Student[i].Score + 2;
101         }
102         for(j=15; j<25; j++)
103         {
104             if(Student[i].Answer[j] == Standard_Answer[j].Correct_Answer)
105             Student[i].Score = Student[i].Score + 3;
106         }
107         for(j=25; j<35; j++)
108         {
109             if(Student[i].Answer[j] == Standard_Answer[j].Correct_Answer)
110             Student[i].Score = Student[i].Score + 4;
111         }
112     }
113 }
114 //------------------计算每个学生的成绩---------------------------------
115 
116 //------------------查询学生成绩---------------------------------------
117 void Student_Score_Look()
118 {
119     int i;
120     char name[32]={0};
121     printf("输入要查询的学生的姓名:\n");
122     scanf("%s", name);
123     for(i=0; i< Stu_Num; i++)
124     {
125         if(strcmp(name, Student[i].Name) == 0)
126         {
127             printf("%d %s的成绩是%d\n", Student[i].Num, Student[i].Name, Student[i].Score);
128         }
129     }
130 }
131 //------------------查询学生成绩---------------------------------------
132 
133 
134 //------------------打印所有学生信息-----------------------------------
135 void Student_All_Score_Print()
136 {
137     int i;
138     for(i=0; i< Stu_Num; i++)
139     {
140         printf("%d %s的成绩是%d\n", Student[i].Num, Student[i].Name, Student[i].Score);
141     }
142 }
143 //------------------打印所有学生信息-----------------------------------
144 
145 //------------------从txt中加载学生信息--------------------------------
146 int Load_File()
147 {
148     FILE* fp;
149     int i=0;
150     int j=0;
151     char line[100][256];
152     fp = fopen("sample.txt", "r+t");
153     if(fp == NULL)
154     {
155         printf("文件打开失败!\n");
156         return -1;
157     }
158     while((fgets(line[i], 256, fp)) != NULL)
159     {
160         line[i][3] = '\0';
161         Student[i].Num = atoi(line[i]);//获取学号
162         for(j=4; j<10; j++)//获取姓名
163         {
164             if(line[i][j] != ' ')
165             {
166                 Student[i].Name[j-4] = line[i][j];
167             }
168         }
169         strcpy(Student[i].Answer, &(line[i][15]));//获取答案
170         i++;
171         Stu_Num++;
172     }
173     fclose(fp);
174     return 0;
175 }
176 //------------------从txt中加载学生信息-----------------------------------
177 
178 //--------按学生成绩排序,tag=1按升序排序,tag=0按降序排序-----------------
179 void Student_All_Score_Sort(const int tag)
180 {
181     int i, j;
182     struct Stu tmp;
183     for(i=0; i<Stu_Num;i++)
184     {
185         for(j=i; j<Stu_Num;j++)
186         {
187             if (Student[i].Score < Student[j].Score)
188             {
189                 memcpy(&tmp, &(Student[i]), sizeof(struct Stu));
190                 memcpy(&(Student[i]), &(Student[j]), sizeof(struct Stu));
191                 memcpy(&(Student[j]), &tmp, sizeof(struct Stu));
192             }
193         }
194     }
195     if(tag == 1)
196     {
197         printf("按升序排列学生成绩:\n");
198         for(i=Stu_Num-1; i>=0; i--)
199         {
200             printf("%d %s的成绩是%d\n", Student[i].Num, Student[i].Name, Student[i].Score);
201         }
202     }
203     else
204     {
205         printf("按升序排列学生成绩:\n");
206         for(i=0; i<Stu_Num; i++)
207         {
208             printf("%d %s的成绩是%d\n", Student[i].Num, Student[i].Name, Student[i].Score);
209         }
210     }
211 }
212 
213 //--------按学生成绩排序,tag=1按升序排序,tag=0按降序排序-----------------
214 
215 
216 //----------------------------------试卷分析------------------------------
217 void Paper_Analyse()
218 {
219     int high=0, low=100;
220     int i;
221     int hege=0;//计算超过60分的学生人数
222     float sum=0, avr;
223     for(i=0; i<Stu_Num; i++)
224     {
225         sum = sum+Student[i].Score;
226         if(Student[i].Score > high)
227             high = Student[i].Score;
228         if(Student[i].Score < low)
229             low = Student[i].Score;
230         if(Student[i].Score >= 60)
231         hege++;
232     }
233     avr = sum/Stu_Num;
234     printf("最高分是:%d\n最低分是:%d\n平均分是:%f\n及格率是:%f\n", high, low, avr, hege*1.0/Stu_Num);
235 }
236 //----------------------------------试卷分析------------------------------
237 
238 
239 int main()
240 {
241     int tag=1;
242     Load_File();//从文件中读取学生信息
243     Standard_Num();//统计标准答案
244     Student_Score_Get();//计算每个学生的分数
245     while(tag != 0)
246     {
247         tag = 0;
248         printf("**************************************************************\n");
249         printf("1.打印标准答案\n");
250         printf("2.根据学生姓名查询学生信息\n");
251         printf("3.按升序打印学生成绩\n");
252         printf("4.按降序打印学生成绩\n");
253         printf("5.打印统计信息\n");
254         printf("0.退出系统\n");
255         printf("请输入你要操作的序号:\n");
256         printf("**************************************************************\n");
257         scanf("%d", &tag);
258         switch(tag)
259         {
260         case 1:Standard_Print();break;
261         case 2:Student_Score_Look();break;
262         case 3:Student_All_Score_Sort(0);break;
263         case 4:Student_All_Score_Sort(1);break;
264         case 5:Paper_Analyse();break;
265         case 0:return 0;
266         default:printf("输入错误!请从新输入:\n");
267         }
268     }
269     return 0;
270 }

测试文件:

 
 1 1   赵光       CADADCDCDACCCDACCBCAAACCDBBCBDDBBAD
 2 2   罗志       CADBDCBCDADCABACBCCACACCAABCBDDBCAB
 3 3   闫谷凡     CDCBDCCCDBDBBBCCBBCACACBAABCBDDBCAB
 4 4   黄智博     CDCBDCCCDBDDABACBDCACACAAABCBDDBCCA
 5 5   汪昇朗     CACBDCBCDBDCBBACBDCACCCAAABCBDDBCAB
 6 6   刘奋伦     CDDBDCDCDBDAABBDDBCBCACAAABCBDDBCAB
 7 7   李磊鹏     CADBDABCDBDCABCCBDBACCCAABBCBDDBCAB
 8 8   高卫       DADBDDBCDBDCBCCCBDCBCACBAABCBDDADAA
 9 9   周鸿韵     CADBDCCBCADCBCDCABCCCACADBBCDCDBDAA
10 10  杨建       CBDBDBBCDBDBBCCABDBACACBABBCBDAADAB
11 11  李海凯     CADBDCACDBDCBDADDADABAACBBBCBDDBCAB
12 12  李冲谱     CADBDCCCDBDCBBACBBCACACAABBCBDDBCAB
13 13  邰杨敏     CACCDCBCDBDCBCCCBDCDCACABBBCBDDBCAB
14 14  姚畅生     CBDBDCDDDBDCDCCBBDCDCCCADABCBDDACAA
15 15  禤微       CADBDABCDCDCBBCBBDBACCAAABBCBDDBCAB
16 16  丁宁       CADADCBCDBDCBDDCDCCABACABABCBDDBCDD
17 17  乔梦进     CADDDABCDBDCBBCABDBACACBDBBCBDDBCAB
18 18  张华       CADBDCBCDBDCBBCACDCACACAABBCBDDBCAB
19 19  代怡康     CADBDABBDBDCBCDABDCBCCCAAABCBDDBCAB
20 20  张文剑     CABDACCCDBDCBCCCBCDBCCABBDBBCCDBCCD
21 21  吴汉       AADBACCCDBDABBCCBDCACACABABCBDDBCAB
22 22  刘亚       CADBBABCDADBBCCADBBACACADABCBDDBCAB
23 23  吴璐       CADBDBCCDBDCBBCCBCBACACAABBCBDDBCAB
24 24  唐金       CACBDBACDBDBBCADDCCAAACBCABCBDDBCAB
25 25  刘秋       CADCDABCDADCBCDADDBCCAAABBBCBDDBCAB
26 26  徐文       CADBDDBCDBDCBBAABDBACCCADBBCBDDACAB
27 27  孙育夫     CABDDCBCDBDCBBDCBDCAACCCDBBCBDDBCCA
28 28  毛东       CDABDDBCDBDCBCCADDCACCCAABBCBDDBCAB
29 29  陈环勇     CADBDABCDBDCBBACCABACCCAABBCBDDBCCB
30 30  郑彪爽     CBDBCCDBBAACBADBCBDDAACCDBBCCDDBCAB
31 31  赵志龙     CADBDDBCDBDABBDABDBACCCBAABCBDDBCAB
32 32  梁傲朝     CADBDABCDBDBBBDCDDCACAAADBBCBDDBCAA
33 33  许同雷     CADBDABCDBDABBBCBDCDCACAABBCBDDBCAB
34 34  徐彦楠     CADBDCBCDBDCBBACDDCACCAABABCBDDBCAB
35 35  罗建磊     CADBDCCCDBDCBCDADBCAACACBBBCBDDBBAD
36 36  曾少林     CBDBDCBCBADDCCADDABACAABCBBCADDBAAB
37 37  郭磊杰     CADBDBBCDACCABDCDDBBCAADBBBCBDDBCAD
38 38  閤道炜     CADBDCBCDBDBADBCABDCCACABBBCBDDADCD
39 39  胡风波     DADBDDBCDBDCBBCCBDBAACCABBBCBDDACAB
40 40  张兆       CDDBDADCDBDCBCCDDDBACAACDBBCBDDBDAB
41 41  吴雪       BDDBDCBCDBDCBDDCBDCACAAAABBCBDDBCCA
42 42  卫曦群     CADBDDACDBDCBBCCDCCACCCAABBCBDDBCCA
43 43  郭文雪     CBDBDDBCDBDBCCCCBBCACAAAABBCBBDBCCB
44 44  黄甘亮     CBDBDCBCDBDBADBCDDCCAACADABCDDDBCBA
45 45  苏子淇     CADBDCBCDBCCBCACADBACACDAABCBCDACCA
46 46  王樊聪     CBDBDCBCDBDCABABBDCACCCAAABCBDDACAB
47 47  肖勇杰     CADBDCBCDBDCBBCCBDCACCCAABBCBDDBCAB
48 48  石小       CCDBDDCCDBDBBBCCCBCAAAADCBBCBDDBCAB
49 49  刘大远     CADBDCCCDBDBADCCADCCCAAAAABCADDCCCA
50 50  陈世怡     CADBDCCCDBDABCCCDDCAAAACAABCADDACCA
51 51  王鹏康     CADBDCDCDCCACCDDBDCABAAACBBCBDDBCAB
52 52  解欣琦     BBDBADCDDBACADBACBDDAADABABCACDBCAA
53 53  刘周雯     CADBDCCCDBDCBCACBACACCCADABCBDDACAB
54 54  代博涛     CADBDBBCDBDBBCDCDABDCCABBABCBDDACAB
55 55  刘亚明     CADBDCDCDBDABBAABABACACAABBCBDDBCAB
56 56  韩建昊     CADBDBBCDBDCBBCBBDBACCCAABBCBDDBCAB
57 57  于磊思琪   CBDCDCCCDBDBBDCAACDACAAADBBBBDABCCA
58 58  王治       DADBDBBCDBDCBBCABDBCCCCAABBCBDDBCAD
59 59  刘春东     CADBDCBCDBDBBBCCADDACAAAAABCBDDBCAB
60 60  魏恒宇     CACBDCBCDBDCBBDCBDBACACBABBCBCDBCAB
61 61  陈春迪     CADBDCBCDBDCBBCCBBBACAABBBBCBDDBCCD
62 62  贾汝远     CADBDBBCDBDBCADABDCBAACCBABCACDBCAB
63 63  韩全彤     CADBDCBCDBDCBBCCBDBACACAABBCBDDCCAB
64 64  付彬祺     CADBDCBCDADABBDCDDBACACBABBCBDDBCBB
65 65  王泽文     CADBBCBCDBDACDBBBBCDBAADBBBCBCDACAB
66 66  胡富南     CADBDCDCDACCBDCCCABACCCDBBBCBDDBCAB
67 67  肖秋来     CADDDCBCDBCCBCACDCBABACCAABBBDDACCA
68 68  周晓       CADBDABCDADCBCCDBDBACCCAABBCBDDBCAB
69 69  王奕敏     CADBDCBCDBDCBBCABDBACCCAABBCBDDBCAB
70 70  徐钰英     DADBDABCDBDCABCCBDBBCCCABBBCBDCBCAB
71 71  陈赢       CDDBAABCBADABCCCDBCACACDAABCBDDBCAB
72 72  杨君       CADBDDACCBDCBDDCBCCCCCCCCBBCBDDBCAB
73 73  李清雪     DADBDCBCDBDCABDCBDCACCCAABBCBDDBCAB
74 74  周俊蒙     CADBCDBCCCDCBDBCBCCACACBBBBCBDDACAB
75 75  李梦       CACBDCBCDBDCBAACBDCACACCBABCBDDBCAB
76 76  夏焕宏     CBDBDCCCDADABBDCBCCAACAADBBBBDDBCDD
77 77  徐鑫强     CADBDCBCDBDAAADCBBCABACAABBCBDDBCAB
78 78  娄克瑞     CACBDBBCCBDCBBDABACACAAAAABCBDABCAB
79 79  董泽光     CDDCDABCDBDDBCDDDCBACACBBABCBDDBBCD
80 80  黄念龙     CACBDABCDBDABBCCBDCACCCAABBCBDDBCAB
81 81  林世       CADBDCBCDBDABAACBDBACCCAABBCBDDBCAB
82 82  王雪       CADBDCBCDBDCBBCABDBACACAABBCBDDBCAB
83 83  何璐       CADCDBBCDBDCCBACBDBCCACAABBCBDDBCAB
84 84  吴一       CBDBDCACBBDCBCACBDCCCACADBBCBDDBCAB
85 85  龚文杰     CADBDCBCDBDCBBCBBDCACCCBAABCBDDBCAB
86 86  王志媛     DAABDCACDBDCCCCCBDCAAACCCABCACDBCCA
87 87  段靖章     CADBDCBCDCDCBBDABDBACAACABBCBCDBCAB
88 88  胡大       CADBDCCCDBDBBDDCBDDCCACAAABBBCDBCBB
89 89  黄利伟     CADBDCBCDBDCABDCCDBACACCADBCBDDBCAB
90 90  张文源     CADBDCBCDBDCBBDABDBACCCAABBCBDDBCAB
91 91  林涛       CADBDBBCDBDCBBCABDBACCCAABBCBDDBCAB

 

posted @ 2016-01-11 20:01  指间ゝ繁华初逝的格调  阅读(606)  评论(0编辑  收藏  举报