C語言成績分析系統(tǒng),可以實現(xiàn)七個功能。(使用的編譯器是 code::blocks)
- 主要實現(xiàn)對於學生信息的輸入
- 顯示輸入學生的信息
- 根據(jù)期末成績來進行排名。
- 查找某個學生的信息
- 刪除某個學生的信息
- 修改某個學生的信息
- 退出程序
七個不同的功能均用自定義函數(shù)來進行完成。對於函數(shù)的命名要起好對應的名字。以免造成混亂,分不清楚自己寫的函數(shù)應該放在哪個位置。
在主函數(shù)使用 switch-case語句來實現(xiàn)函數(shù)的調(diào)用功能。
一些遇到的問題
1、 在codeblocks IDE中中文會出現(xiàn)亂碼的情況
(1) 是字體庫不匹配的原因,重新選擇字體庫可以解決輸入中文

(2) 對IDE編輯器進行環(huán)境調(diào)試。
點擊Other compiler options,在空白處填寫:
-finput-charset=UTF-8
-fexec-charset=GBK

2、 在進行學號輸入時對int和char類型的選擇
(1)考慮到學號的長短不一,對于用戶而言,選擇相對于自由,可以選則無符號整形(學號沒有負數(shù)的可能),或者時字符型數(shù)組來進行存儲,則可以解決較長的學號。
(2)在選擇方面,在程序中我使用了無符號的整形來儲存較長的學號,注意在使用打印printf函數(shù)時要用%lld,但是相比較而言,選擇字符型數(shù)組更好。(可以設置字符型數(shù)組char num[50])。
3、 在需要不同功能的函數(shù)塊可以使用新的的結(jié)構(gòu)體數(shù)組來進行快速的設定,這樣可以方便以后的查改。
4、 在定義數(shù)組的元素個數(shù)時,可以使用宏來定義,方便程序的維護。
1 /*程序中默認期末成績=平時分的百分之40+實驗成績的百分之60*/ 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include <string.h> 5 #include<stdbool.h> 6 #define NUM 100 7 struct Stu //定義學生結(jié)構(gòu)體 8 { 9 char name[30]; //姓名 10 char gender[20]; //性別 11 long long number; //學號 12 double Uscore; //平時分數(shù) 13 double Escore; //實驗成績 14 double Fscore; //期末成績 15 }; 16 17 struct Stu Student[100]; //一共可以儲存100個學生的信息 18 19 int n; //全局變量 20 int allfuction; 21 22 void Exit() //顯示退出程序函數(shù)(結(jié)束) 23 { 24 system("cls"); 25 printf("\n\n\n"); 26 printf("\t\t\t****************************************************************\n"); 27 printf("\t\t\t|| ||\n"); 28 printf("\t\t\t|| Thank you to ||\n"); 29 printf("\t\t\t|| use this programme ! ||\n"); 30 printf("\t\t\t|| ||\n"); 31 printf("\t\t\t|| ||\n"); 32 printf("\t\t\t****************************************************************\n"); 33 } 34 35 void Menu() //菜單 36 { 37 38 printf(" *************************Student achievement management system************************\n"); 39 printf(" Please select the operation to be performed\n \n"); 40 printf(" 1 : Enter the information of students you want.\n"); 41 printf(" 2 : Show all students information.\n"); 42 printf(" 3 : Sort students information.\n"); 43 printf(" 4 : Find students information.\n"); 44 printf(" 5 : Delete students information.\n"); 45 printf(" 6 : Modify students information\n"); 46 printf(" 7 : Exit this system.\n"); 47 printf("Please enter your options: \n"); 48 scanf("%d",&allfuction); 49 } 50 51 int InputStudent() //學生基本信息輸入int組 52 { 53 int again; 54 int i=1; 55 while(i) 56 { 57 system("cls"); 58 printf("--------------Please enter students\' information--------------\n\n\n"); //人機交互 59 printf("Please enter the score of the number %d student:\n",i); //提示用戶輸入 60 printf("Please enter student\'s ID:"); 61 scanf("%lld",&Student[i].number); //結(jié)構(gòu)體的數(shù)據(jù)輸入number 62 printf("Please enter student\'s name:"); 63 scanf("%s",Student[i].name); //結(jié)構(gòu)體的數(shù)據(jù)輸入name 64 printf("Please enter student\'s gender:"); 65 scanf("%s",&Student[i].gender); //結(jié)構(gòu)體的數(shù)據(jù)輸入gender 66 printf("Please enter student\'s Semester work:"); 67 scanf("%lf",&Student[i].Uscore); //結(jié)構(gòu)體的數(shù)據(jù)輸入Uscore 68 printf("Please enter student\'s Experimental results:"); 69 scanf("%lf",&Student[i].Escore); //結(jié)構(gòu)體的數(shù)據(jù)輸入Escore 70 i++; //計數(shù)器 71 n++; 72 printf("Success!\n"); 73 printf("Continue to decide whether to enter information ? 1.Continue 2.Exit\n"); 74 scanf("%d",&again); //讓用戶決定是否繼續(xù)輸入 75 if(again == 2) 76 { 77 system("cls"); //清屏結(jié)束此次操作 78 break; 79 } 80 81 } 82 } 83 84 void DisplayStudent() //顯示學生信息 85 { 86 int i = 0; //初始化i計數(shù)器 87 int pass = 0; 88 int n_pass = 0; 89 double percent=0.0; 90 double percent1=0.0; 91 system("cls"); //清屏實現(xiàn)后續(xù)操作 92 printf("--------------Display students\' information--------------\n\n\n"); 93 printf("ID====name====semester work====Experimental results====Final Examination====\n\n\n"); 94 95 for(i = 1;i <= n; i++) 96 { 97 Student[i].Fscore = (0.4*Student[i].Uscore) + (0.6*Student[i].Escore); //期末成績的計算 98 printf("Student ID:%lld\nStudent name:%s\nSemester work:%.3lf\nExperimental results:%.3lf\nFinal examination:%.3lf\n\n", 99 Student[i].number,Student[i].name,Student[i].Uscore,Student[i].Escore,Student[i].Fscore); //輸出學生的成績信息 100 } 101 if(Student[i].Fscore < 60) 102 { 103 ++n_pass; 104 } 105 else 106 { 107 ++pass; 108 } 109 percent=(double)pass/(double)n; 110 percent1=(double)n_pass/(double)n; 111 printf("%d students pass the assessment. %.3lf%% of the total number of students\n",pass,percent); 112 printf("%d students not pass the assessment. %.3lf%% of the total number of students\n",n_pass,percent1); 113 } 114 115 void mysort() //根據(jù)成績排序名次 116 { 117 struct Stu t; //新的結(jié)構(gòu)體 118 system("cls"); 119 printf("--------------Ranked according to final examination--------------\n\n\n"); 120 for(int i = 1; i < n; i++) 121 for(int j = 1; j < n; j++) 122 if(Student[j].Fscore > Student[j-1].Fscore) //互換 123 { 124 t = Student[j]; 125 Student[j] = Student[j-1]; 126 Student[j-1] = t; 127 } 128 for(int i = 1; i <= n; i++) //按照成績的大小來輸出具體的信息 129 { 130 Student[i].Fscore = (0.4*Student[i].Uscore) + (0.6*Student[i].Escore); 131 printf("Student ID: %d\n",Student[i].number); 132 printf("Student name: %s\n",Student[i].name); 133 printf("Gender: %s\n",Student[i].gender); 134 printf("Semester work: %.3lf\n",Student[i].Uscore); 135 printf("Experimental results: %.3lf\n",Student[i].Escore); 136 printf("Final examination: %.3lf\n\n",Student[i].Fscore); 137 } 138 printf("\n"); 139 } 140 141 void FindStudent() //根據(jù)學號查找錄入學生的信息 142 { 143 int i=0; //計數(shù)器 144 long long ID; //定位學號的一個標記 145 system("cls"); 146 printf("--------------Search by student\'s ID--------------\n\n\n"); 147 printf("Please enter the student\'s ID: "); 148 scanf("%lld",&ID); 149 for(i=1;i<=n;i++) 150 { 151 if(ID==Student[i].number) //如果輸入的學號和存入學生信息的學號相等,進入下面的程序 152 { 153 Student[i].Fscore = (0.4*Student[i].Uscore) + (0.6*Student[i].Escore); 154 printf("Student ID: %lld\n",Student[i].number); 155 printf("Student name: %s\n",Student[i].name); 156 printf("Gender: %s\n",Student[i].gender); 157 printf("Semester work: %.3lf\n",Student[i].Uscore); 158 printf("Experimental results: %.3lf\n",Student[i].Escore); 159 printf("Final examination: %.3lf\n",Student[i].Fscore); 160 } 161 } 162 } 163 164 void DeleteStudent() //刪除一個學生的信息 165 { 166 long long nums; //定義一個學號的標記 167 int i=0; 168 int j=0; 169 int decide; 170 system("cls"); 171 printf("\n============Delete information by student\' ID===========\n"); 172 printf("Enter the student ID of the student you want to delete: "); 173 scanf("%lld",&nums); 174 175 for(i=1;i<=n;i++) 176 { 177 if(nums==Student[i].number) //輸入的學號與存入的學號相等進行刪除工作 178 { 179 Student[i].Fscore = (0.4*Student[i].Uscore) + (0.6*Student[i].Escore); 180 printf("ID\tname\tSemester work\tExperimental results\tFinal examination\t\n"); 181 printf("%lld\t%s\t%.3lf\t%.3lf\t%.3lf\t\n", 182 Student[i].number,Student[i].name,Student[i].Uscore,Student[i].Escore,Student[i].Fscore); 183 184 printf("Confirm the deletion !(1.Yes 2.No)\n"); 185 scanf("%d",&decide); 186 if(decide==1) //輸入1則進行刪除工作 187 { 188 for(j=i;j<=n;j++) 189 { 190 Student[j].number=Student[j+1].number; 191 strcpy(Student[j].name,Student[j+1].name); 192 Student[i].Uscore=Student[i].Uscore; 193 Student[i].Escore=Student[i].Escore; 194 Student[i].Fscore=Student[i].Fscore; 195 } 196 n--; 197 } 198 if(decide==2) //輸入2則取消刪除工作 199 { 200 printf("Cancel deletion."); 201 } 202 } 203 } 204 } 205 206 void ModifyStudent() //修改學生的信息 207 { 208 int i=0; 209 long long IDs; 210 system("cls"); 211 printf("--------------Please enter the student\'s ID you want to modify--------------\n\n\n"); 212 printf("Please enter the student\'s ID you want to modify:"); 213 scanf("%lld",&IDs); 214 for(i = 1; i <= n; i++) 215 { 216 if(IDs==Student[i].number) 217 { 218 printf("Please re-enter the student's information.\n"); 219 printf("ID: \n"); 220 scanf("%lld",&Student[i].number); 221 printf("name: \n"); 222 scanf("%s",Student[i].name); 223 printf("Semester work: \n"); 224 scanf("%lf",&Student[i].Uscore); 225 printf("Experimental results: \n"); 226 scanf("%lf",&Student[i].Escore); 227 printf("Final examination: \n"); 228 scanf("%lf",&Student[i].Fscore); 229 printf("Successful modification !\n\n"); 230 } 231 } 232 } 233 234 int main() 235 { 236 while(true) 237 { 238 Menu(); //顯示菜單 239 240 switch(allfuction) //選擇swtich來進行菜單的選擇 241 { 242 case 1: 243 InputStudent(Student,NUM); //輸入學生信息 244 break; 245 246 case 2: 247 DisplayStudent(Student,NUM); //顯示學生信息 248 break; 249 250 case 3: 251 mysort(Student,NUM); //根據(jù)期末成績排序,并展示及格和不及格的人數(shù) 252 break; 253 254 case 4: 255 FindStudent(Student,NUM); //查找某個學生的信息 256 break; 257 258 case 5: 259 DeleteStudent(Student,NUM); //刪除某個學生的信息 260 break; 261 262 case 6: 263 ModifyStudent(Student,NUM); //修改某個學生的信息 264 break; 265 266 case 7: //退出整個程序 267 Exit(); 268 return 0; 269 } 270 } 271 }
代碼運行結(jié)果以及功能展示
- 菜單
![]()
- 錄入信息
![]()
- 顯示信息
- 根據(jù)期末成績排名
- 查找某個學生的信息
- 刪除某個學生的信息
![]()
- 修改某個學生的信息
- 退出程序




浙公網(wǎng)安備 33010602011771號