源代码:
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, ", 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("输入要查询的学生的姓名: "); 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 ", 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 ", 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("文件打开失败! "); 156 return -1; 157 } 158 while((fgets(line[i], 256, fp)) != NULL) 159 { 160 line[i][3] = '