課程設計 C語言 學生成績管理系統

来源:https://www.cnblogs.com/jiujue/archive/2020/03/01/12391816.html
-Advertisement-
Play Games

學生成績管理系統 tips : 應該寫的註釋都寫了,適合初學者參考。某班最多不超過30人(具體人數由鍵盤輸入),考試科目最多不超過6門(具體門數由鍵盤輸入)。 請編寫一個程式實現如下菜單驅動的學生成績管理系統;要求:(1)錄入每個學生 的學號、姓名和各科考試成績。(2)計算每門課程的總分和平均分。( ...


學生成績管理系統

tips : 應該寫的註釋都寫了,適合初學者參考。
某班最多不超過30人(具體人數由鍵盤輸入),考試科目最多不超過6門(具體門數由鍵盤輸入)。

請編寫一個程式實現如下菜單驅動的學生成績管理系統;要求:
(1)錄入每個學生 的學號、姓名和各科考試成績。
(2)計算每門課程的總分和平均分。
(3)計算每個學生的總分和平均分。
(4)按每個學生的總分由高到低排出名次表。
(5)按學號由小到大排出成績表。
(6)按姓名的字典順序排出成績表。
(7)按學號查詢學生排名及各科考試成績。
(8)按姓名查詢學生排名及各科考試成績。
(9)按優秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5個類別,對每門課程分別統計每個類別的人數及所占的百分比。
(10)輸出每個學生的學號、姓名、各科考試成績、總分、平均分,以及每門課程的總分和平均分。

code(可直接運行):

  1 #define  _CRT_SECURE_NO_WARNINGS
  2 #include <stdio.h>
  3 #include <string.h>
  4 #include<stdlib.h>
  5 
  6 struct Course {
  7     int C_score;
  8     char C_name[10];
  9 };
 10 struct Stu {
 11     int id;
 12     char name[10];
 13     struct Course courses[6];
 14     int total_score;
 15     int ave;
 16     int ranking;
 17 };
 18 struct Stu stu[30];
 19 int real_stu;
 20 int real_cou;
 21 int temp[30] = { 0 };
 22 int temp_forFun7[30] = { 0 };    //這裡在函數5中修改了 temp ,但是fun7 要用,所以但copy出來一個。
 23 int C_total_score[6] = { 0 };
 24 int C_ave[6] = { 0 };
 25 
 26 enum level {
 27     優秀 = 0, 良好, 中等, 及格, 不及格
 28 };
 29 
 30 int getRanking(int id);
 31 struct Stu* getStu(int id);
 32 char* getLevel(int num);
 33 
 34 int fun0();
 35 int fun1();
 36 int fun2();
 37 int fun3();
 38 int fun4();
 39 int fun5();
 40 int fun6();
 41 int fun7();
 42 int fun8();
 43 int fun9();
 44 int fun10();
 45 int main()
 46 {
 47     while (1) {
 48         //輸入數字幾,則運行程式幾
 49         switch (fun0()) {
 50         case  0: exit(0); break;
 51         case  1: fun1(); break;
 52         case  2: fun2(); break;
 53         case  3: fun3(); break;
 54         case  4: fun4(); break;
 55         case  5: fun5(); break;
 56         case  6: fun6(); break;
 57         case  7: fun7(); break;
 58         case  8: fun8(); break;
 59         case  9: fun9(); break;
 60         case 10: fun10(); break;
 61         case 11:/*fun11()*/; break;
 62         }
 63     }
 64 
 65     return 0;
 66 }
 67 
 68 
 69 //0菜單
 70 int fun0() {
 71     //菜單
 72     int n;
 73     printf("*******************************************************\n");
 74     printf("1. 錄入每個學生 的學號、姓名和各科考試成績.\n");
 75     printf("2. 計算每門課程的總分和平均分。\n");
 76     printf("3. 計算每個學生的總分和平均分。\n");
 77     printf("4. 按每個學生的總分由高到低排出名次表。\n");
 78     printf("5. 按學號由小到大排出成績表。\n");
 79     printf("6. 按姓名的字典順序排出成績表。\n");
 80     printf("7. 按學號查詢學生排名及各科考試成績。\n");
 81     printf("8. 按姓名查詢學生排名及各科考試成績。\n");
 82     printf("9. 按優秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5個類別,對每門課程分別統計每個類別的人數及所占的百分比。\n");
 83     printf("10.輸出每個學生的學號、姓名、各科考試成績、總分、平均分,以及每門課程的總分和平均分。\n");
 84     printf("0. Exit\n");
 85     printf("*******************************************************\n");
 86     printf("    Please enter your choice :\n");
 87     scanf_s("%d", &n);
 88     return n;
 89 }
 90 
 91 //1,錄入每個學生的學號、姓名和各科考試成績。
 92 int fun1() {
 93     //(1)錄入每個學生的學號、姓名和各科考試成績。
 94     printf("請輸入總人數(不超過30人):");
 95     scanf("%d", &real_stu);
 96     printf("請輸入總課程數(不超過6門):");
 97     scanf("%d", &real_cou);
 98 
 99     //(1)錄入、每個 學生 的學號、姓名和各科考試成績。
100     for (int i = 0; i < real_stu; i++) {//錄入第 i 個學生信息:學號 姓名。
101         printf("請輸入第 %d 個學生的信息  ( 輸入格式提示 例如:[學號 姓名] 中括弧裡面的為一次錄入,不用寫中括弧。)\n", i + 1);
102         scanf("%d %s", &(stu[i].id), stu[i].name);
103 
104         printf("請輸入需要錄入課程的信息  ( 輸入格式提示 例如:[課程名字 課程分數] 中括弧裡面的為一次錄入,不用寫中括弧。)\n");
105         for (int j = 0; j < real_cou; j++) {//錄入第 i 個學生課程信息:課程名字 分數。
106             scanf("%s %d", stu[i].courses[j].C_name, &(stu[i].courses[j].C_score));
107         }
108     }
109     return 0;
110 }
111 
112 //2,計算每門課程的總分和平均分
113 int fun2() {
114     //(2)計算每門課程的總分和平均分
115 
116     for (int i = 0; i < real_stu; i++) {
117         for (int j = 0; j < real_cou; j++) {
118             C_total_score[j] += stu[i].courses[j].C_score;
119         }
120     }
121     for (int i = 0; i < real_stu; i++) {
122         C_ave[i] = C_total_score[i] / real_stu;//第i門課的平均分
123     }
124     //最後不用print
125     for (int i = 0; i < real_cou; i++) {
126         printf("%d  %d\n", C_total_score[i], C_ave[i]);
127 
128     }
129     return 0;
130 }
131 
132 //3,計算每個學生的總分和平均分。
133 int fun3() {
134     //(3)計算每個學生的總分和平均分。
135     for (int i = 0; i < real_stu; i++) {//第幾個學生
136         for (int j = 0; j < real_cou; j++) {//第幾門課
137             stu[i].total_score += stu[i].courses[j].C_score;
138         }
139     }
140     for (int i = 0; i < real_cou; i++) {
141         stu[i].ave = stu[i].total_score / real_cou;
142     }
143     for (int i = 0; i < real_stu; i++) {
144         printf("第%d個學生的總分為%d\n", i + 1, stu[i].total_score);
145         printf("第%d個學生的平均分為 % d\n", i + 1, stu[i].ave);
146     }
147     return 0;
148 }
149 
150 //4,按每個學生的總分由高到低排出名次表。
151 int fun4() {
152     //(4)按每個學生的總分由高到低排出名次表。
153     for (int i = 0; i < real_stu; i++) {
154         temp[i] = stu[i].id;    //創建數組,存id,通過id找到信息
155     }
156     int temp_for_swap = 0;
157     //排序
158     for (int i = 0; i < real_stu - 1; i++) {//輪次,n-1次
159         for (int j = 0; j < real_stu - i - 1; j++) {//一次排序
160             if (getStu(temp[j])->total_score < getStu(temp[j + 1])->total_score) {
161                 //交換 temp[i] temp[i+1]
162                 //t_temp,為中間作為交換的數組,存放id
163                 //temp數組為存放id數組
164                 temp_for_swap = temp[j];
165                 temp[j] = temp[j + 1];
166                 temp[j + 1] = temp_for_swap;
167             }
168         }
169     }
170     //輸出
171     printf("按每個學生的總分由高到低排出的名次表為\n");
172     for (int i = 0; i < real_stu; i++) {
173         printf("%d %s %d\n", getStu(temp[i])->id, getStu(temp[i])->name, getStu(temp[i])->total_score);
174     }
175     //這裡在函數5中修改了 temp ,但是fun7 要用,所以但copy出來一個。
176     memcpy(temp_forFun7,temp,real_stu);
177     return 0;
178 
179 }
180 
181 //5,按學號由小到大排出成績表。
182 int fun5() {
183     //(5)按學號由小到大排出成績表。
184     //排序,學號大小,也就是說,輸入不一定按學號從小到大輸入
185     int temp_for_swap = 0;
186     //排序
187     for (int i = 0; i < real_stu - 1; i++) {//輪次,n-1次
188         for (int j = 0; j < real_stu - i - 1; j++) {//一次排序
189             if (getStu(temp[j])->id > getStu(temp[j + 1])->id) {
190                 //交換 temp[i] temp[i+1]
191                 //t_temp,為中間作為交換的數組,存放id
192                 //temp數組為存放id數組
193                 temp_for_swap = temp[j];
194                 temp[j] = temp[j + 1];
195                 temp[j + 1] = temp_for_swap;
196             }
197         }
198     }
199     printf("按每個學生的按學號由小到大排出成績表為\n");
200     for (int i = 0; i < real_stu; i++) {
201         printf("%d %s %d\n", getStu(temp[i])->id, getStu(temp[i])->name, getStu(temp[i])->total_score);
202     }
203     return 0;
204 }
205 
206 //6,按姓名的字典順序排出成績表。
207 int fun6() {
208     //(6)按姓名的字典順序排出成績表。
209     //字典順序,成績表
210     //字元串比較
211     int temp_for_swap = 0;
212     for (int i = 0; i < real_stu - 1; i++) {
213         for (int j = 0; j < real_stu - i - 1; j++) {
214             if (strcmp(getStu(temp[j])->name, getStu(temp[j + 1])->name) > 0) {
215                 temp_for_swap = temp[j];
216                 temp[j] = temp[j + 1];
217                 temp[j + 1] = temp_for_swap;
218             }
219         }
220     }
221     //print
222     printf("按學生姓名的字典順序排出成績表為\n");
223     for (int i = 0; i < real_stu; i++) {
224         printf("%d %s %d\n", getStu(temp[i])->id, getStu(temp[i])->name, getStu(temp[i])->total_score);
225     }
226     return 0;
227 }
228 //7,按學號查詢學生排名及各科考試成績。
229 
230 int fun7() {
231     //按學號查詢學生排名及各科考試成績。
232     for (int i = 0; i < real_stu; i++) {
233         getStu(temp_forFun7[i])->ranking = getRanking(temp_forFun7[i]);//排名,由get函數初始化
234     }
235     int input_id;
236     printf("請輸入需要查詢成績的學生的學號:");
237     scanf("%d", &input_id);
238 
239     struct Stu* hit_stu = getStu(input_id);//把用getStu函數找到的學生信息,給hit——stu
240 
241     printf("學號為%d的學生是%s\n", hit_stu->id, hit_stu->name);
242     printf("排名為%d\n", hit_stu->ranking + 1);
243     printf("其各科成績為:\n");
244     for (int i = 0; i < real_cou; i++) {
245         printf("%s %d\n", hit_stu->courses[i].C_name, hit_stu->courses[i].C_score);
246     }
247     return 0;
248 }
249 //8,按姓名查詢學生排名及各科考試成績。
250 int fun8() {
251     //(8)按姓名查詢學生排名及各科考試成績。
252     char input_name[10] = { 0 };
253     printf("請輸入需要查詢成績的學生的姓名:");
254     scanf("%s", input_name);
255 
256     struct Stu* hit_stu = NULL;
257     for (int i = 0; i < real_stu; i++) {
258         if (strcmp(hit_stu->name, input_name) == 0) {
259             hit_stu = &stu[i];
260         }
261     }
262     if (hit_stu == NULL) {
263         printf("姓名為%s的學生不存在\n", input_name);
264         return;
265     }
266 
267     printf("學號為%d的學生是%s\n", hit_stu->id, hit_stu->name);
268     printf("排名為%d\n", hit_stu->ranking + 1);
269     printf("其各科成績為:\n");
270     for (int i = 0; i < real_stu; i++) {
271         printf("%s %d\n", hit_stu->courses[i].C_name, hit_stu->courses[i].C_score);
272     }
273     return 0;
274 }
275 //(9)按優秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5個類別,對每門課程分別統計每個類別的人數及所占的百分比。,switch語句,除以總人數,然後列印
276 int fun9() {
277 
278     //(9)按優秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5個類別,
279 //對每門課程分別統計 每個類別的人數及所占的百分比。,除以總人數,然後列印
280     //等價於 int type [][];
281     // type[ 第幾門課 ] [ 該課的類別 ]
282     //int** type = (int**)malloc(sizeof(int) * 5 * real_cou);
283     float type[6][5] = {0};
284     for (int i = 0; i < real_stu; i++) {
285         for (int j = 0; j < real_cou; j++) {
286             //type[i][j];
287             int temp_score = stu[i].courses[j].C_score;
288             if (temp_score >= 0 && temp_score < 59) {
289                 type[j][不及格] += 1;//bad
290             }
291             else if (temp_score >= 60 && temp_score < 69) {
292                 type[j][及格] += 1;//及格
293             }
294             else if (temp_score >= 70 && temp_score < 79) {
295                 type[j][中等] += 1;//中等
296             }
297             else if (temp_score >= 80 && temp_score < 89) {
298                 type[j][良好] += 1;//良好
299             }
300             else if (temp_score >= 90 && temp_score < 100) {
301                 type[j][優秀] += 1;//優秀
302             }
303         }
304     }
305 
306     //float** ratio = (float**)malloc(sizeof(float) * 5 * real_cou);
307     float ratio[6][5] = { 0.0 };
308 
309     for (int i = 0; i < real_cou; i++)
310     {
311         for (int j = 0; j < 5; j++)
312         {
313             ratio[i][j] = type[i][j] / real_stu;
314         }
315 
316     }
317 
318     //print
319     for (int i = 0; i < real_cou; i++)
320     {
321         printf("第 %d 課程的各等級占比為:\n", i);
322         for (int j = 0; j < 5; j++)
323         {
324             printf("\t\t %s 占比 %f: \n", getLevel(j), ratio[i][j]);
325         }
326 
327     }
328 
329     return 0;
330 }
331 //(10)輸出每個學生的學號、姓名、各科考試成績、總分、平均分,以及每門課程的總分和平均分。
332 int fun10() {
333     for (int i = 0; i < real_stu; i++)
334     {
335         printf("姓名為%s\t學號為%d\t學生總分為%d\t平均分為%d\n", getStu(temp[i])->name, getStu(temp[i])->id, getStu(temp[i])->total_score, getStu(temp[i])->ave);
336         for (int j = 0; j < real_cou; j++) {
337             printf("\t科目為:%s \t考試成績為: %d\t科目總分: %d\t科目平均分 :%d 。\n", 
338                 getStu(temp[i])->courses[j].C_name, getStu(temp[i])->courses[j].C_score, C_total_score[i], C_ave[i]);
339         }
340     }
341     return 0;
342 }
343 
344 int getRanking(int id) {
345     for (int i = 0; i < real_stu; i++) {
346         if (id == temp[i]) {
347             return i;//i即為排名
348         }
349     }
350 }
351 struct Stu* getStu(int id) {
352     for (int i = 0; i < real_stu; i++)
353     {
354         if (stu[i].id == id) {
355             return &stu[i];
356         }
357     }
358     return NULL;
359 }
360 
361 char* getLevel(int num) {
362     //enum level {
363     //    優秀 = 0, 良好, 中等, 及格, 不及格
364     //};
365     switch (num)
366     {
367     case 0:
368 
369         return "優秀";
370     case 1:
371 
372         return "良好";
373     case 2:
374 
375         return "中等";
376     case 3:
377 
378         return "及格";
379     case 4:
380 
381         return "不及格";
382     default:
383         return "unknown";
384     }
385 }
View Code

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 先用一個數組表示一個二叉樹搜索樹,也就是一個排好序的二叉樹,其中左子結點<根結點<右子結點 利用結構數組的形式來表示,id , left , right 代表結點id ,左子樹 ,右子樹 下麵這個二維數組 $data[]=['id'=>8,'left'=>2,'right'=>10,'data'=> ...
  • 上一篇我們已經根據路徑讀取到了我們需要的位元組碼文件,就以java.lang.Object這個類為例,可以看到類似下麵這種東西,那麼這些數字是什麼呢? 要瞭解這個,我們大概可以猜到這是十進位的,線上將十進位轉為十六進位看看https://tool.oschina.net/hexconvert/,註意上 ...
  • [TOC] 下麵介紹pandas常見的基本功能,和python的基本數據類型進行比較可以看到pandas在操作大型數據集中的優勢。 1.重建索引 (1)函數:reindex (2)作用:創建一個符合新索引的新對象。 (3)內容: Series調用reindex方法時,會將數組按照新的索引進行排列,如 ...
  • 基於JSP+Servlet開發失物招領系統開發環境: Windows操作系統開發工具:Myeclipse+Jdk+Tomcat7+MYSQL資料庫運行效果圖 源碼及原文鏈接:https://javadao.xyz/forum.php?mod=viewthread&tid=115 ...
  • 基於JSP+Servlet開發公交線上查詢(前臺+後臺):( 開發環境: Windows操作系統開發工具: Eclipse+Jdk+Tomcat+MYSQL資料庫運行效果圖 源碼及原文鏈接:https://javadao.xyz/forum.php?mod=viewthread&tid=120 ...
  • @[toc] 1. Spring註解的源碼分析 1.1 我如何開始分析源碼的? ==這一部分可以略過直接看第1.2節== 想必程式員都會經過這樣一個階段,當 已經能夠熟練運用。並且它的 也能夠用到 ,程式員就會找進階的入口,這時候就想到了去瞭解源碼。 作為Java程式員,首先想到的一定是瞭解Spri ...
  • React非常快速是因為它從不直接操作DOM。 虛擬DOM是在DOM的基礎上建立了一個抽象層,對數據和狀態所做的任何改動,都會被自動且高效的同步到虛擬DOM,最後再批量同步到DOM中。 在React中,render執行的結果得到的並不是真正的DOM節點,而僅僅是JavaScript對象,稱之為虛擬D ...
  • 教程共分為五篇,從AOP實例的構建及其重要組件、基本運行流程、容器創建流程、關鍵方法調用、原理總結歸納等幾個方面一步步走進AOP的世界。 本篇主要為讀者演示構建AOP實例及AOP核心組件分析。 一、項目構建 讀者可直接下載示例工程,或複製以下的代碼到本地工程開啟教程。 <?xml version=" ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...