日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C语言课设 成绩管理程序

發布時間:2024/2/28 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C语言课设 成绩管理程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

成績管理程序

功能:
(1) 錄入若干個學生每門課程的分數;
(2) 給定學號,顯示某位學生所有課程成績;
(3) 給定某個班級的班號,顯示該班所有學生的課程成績情況;
(4) 給定學號,修改該學生的課程成績信息;
(5) 按照某門課程的成績從高到低排序;
(6) 提供一些統計各類信息的功能(例如,某門課程不及格名單、某門課程的總平均成績等)

關于本程序

  • 連續按三次ctrl z可以返回上一級菜單
  • 請按照正常順序,一級一級退出,不要直接點擊右上角關閉程序。否則,data.txt可能沒有完全寫入
  • 想即時保存也行,每次操作完成之后加一句writeData(&phead, &ptail);即可
  • 你可以直接在txt中進行修改成績操作,且不必輸入總分、平均分,但一定要保證:格式正確

txt存儲格式如下

  • 總人數
  • 學號 姓名 班級 數學 英語 政治 體育 物理 總分 平均分

程序文件構成 (見左側解決方案資源管理器)

運行環境:vs2017

以下為全部代碼

main.c

/* ===================================成績管理程序===================================* 注意:* 連續按三次ctrl z可以返回上一級菜單* 請按照正常順序,一級一級退出,不要直接點擊右上角關閉程序。否則,data.txt可能沒有完全寫入* 想即時保存也行,每次操作完成之后加一句writeData(&phead, &ptail);即可* 你可以直接在txt中進行修改成績操作,且不必輸入總分、平均分,但一定要保證:格式正確** txt存儲格式如下:* 總人數* 學號 姓名 班級 數學 英語 政治 體育 物理 總分 平均分*==================================================================================*/#include"list.c" #include"sort.c" #include"read.c" #include"write.c" int main() {int i;pstu phead = NULL;pstu ptail = NULL;readData(&phead, &ptail);//更新數據(若用戶直接操作txt文件,該函數可以自動計算新的總分、平均分)update(&phead, &ptail);//選擇想要的操作int choose;while (printHome(), printf("\n請輸入你選擇的操作:"), scanf("%d", &choose) != EOF){rewind(stdin);system("cls");switch (choose){case 1://while (system("cls"), list_print(phead, ptail), printf("(三次ctrl z返回上一級)\n請輸入要添加的學號:"), scanf("%d", &i) != EOF){rewind(stdin);list_insert_sort(&phead, &ptail, i);}writeData(&phead, &ptail);break;case 2://while (system("cls"), list_print(phead, ptail), printf("(三次ctrl z返回上一級)\n請輸入刪除的學號:"), scanf("%d", &i) != EOF){rewind(stdin);list_delete(&phead, &ptail, i);}writeData(&phead, &ptail);break;case 3://while (system("cls"), list_print(phead, ptail), printf("(三次ctrl z返回上一級)\n請輸入修改的學號:"), scanf("%d", &i) != EOF){rewind(stdin);list_modify(&phead, &ptail, i);}writeData(&phead, &ptail);break;case 4://while (system("cls"), printf("(三次ctrl z返回上一級)\n請輸入查找的學號:"), scanf("%d", &i) != EOF){rewind(stdin);list_find(&phead, &ptail, i);}writeData(&phead, &ptail);break;case 5://排序while (system("cls"), printf("(三次ctrl z返回上一級)\n請輸入排序依據:\n1總分 2數學 3英語 4政治 5體育 6物理 7學號\n"), scanf("%d", &i) != EOF){rewind(stdin);arr_select(&phead, &ptail, i);list_print(phead, ptail);system("pause");}writeData(&phead, &ptail);break;case 6://統計信息while (system("cls"), printf("(三次ctrl z返回上一級)\n請輸入要查看的數據編號:\n(一)不及格名單(小于60分)\n11 數學\n12 英語\n13 政治\n14 體育\n15 物理\n\n(二) 成績優秀名單(大于90分)\n21 數學\n22 英語\n23 政治\n24 體育\n25 物理\n\n(三) 課程平均成績\n31 數學\n32 英語\n33 政治\n34 體育\n35 物理\n\n(四) 按班級分類\n41 輸出某個班的成績\n"), scanf("%d", &i) != EOF){rewind(stdin);statistics(&phead, &ptail, i);}break;}}writeData(&phead, &ptail);//雞肋的保存 }

head.h

#ifndef __FIRST__H_H #define __FIRST__H_H #define COURSENUM 5typedef struct student {int id;char name[20];int classnum;int math;int english;int politics;int sports;int physics;int total;int average;struct student *pnext; }stu, *pstu; #endif

list.c

#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include"head.h" //打印首頁 void printHome() {system("cls");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * *\n");printf(" * 學 生 成 績 管 理 系 統 *\n");printf(" * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * *\n");printf(" * * 1.添 加 學 生 * 2.刪 除 學 生 *\n");printf(" * 功 * * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");printf(" * 能 * * *\n");printf(" * * 3.修 改 成 績 * 4.查 找 學 生 *\n");printf(" * 菜 * * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");printf(" * 單 * * *\n");printf(" * * 5.按 要 求 排 序 * 6.統 計 信 息 *\n");printf(" * * * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * *\n");printf(" * 提 示 :任 意 界 面 下 , 連 續 三 次 ctrl z 返 回 上 一 級 *\n");printf(" * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");}//打印總表 void list_print(pstu phead, pstu ptail) {int flag = 0;pstu pcur = phead;printf("學號\t姓名\t班級\t數學\t英語\t政治\t體育\t物理\t總分\t平均分\n");while (pcur != NULL){flag = 1;printf("%d\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", pcur->id, pcur->name, pcur->classnum, pcur->math, pcur->english, pcur->politics, pcur->sports, pcur->physics, pcur->total, pcur->average);pcur = pcur->pnext;}flag == 0 || printf("\n");//空表時不打印換行 }//打印當前學生 void printOne(stu one) {printf("學號\t姓名\t班級\t數學\t英語\t政治\t體育\t物理\t總分\t平均分\n");printf("%d\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", one.id, one.name, one.classnum, one.math, one.english, one.politics, one.sports, one.physics, one.total, one.average); } void printOneNoHead(stu one) {printf("%d\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", one.id, one.name, one.classnum, one.math, one.english, one.politics, one.sports, one.physics, one.total, one.average); } //打印統計信息 void statistics(pstu *pphead, pstu *pptail, int i) {int flag = 0;pstu pcur = *pphead;if ((i >= 11 && i <= 15) || (i >= 21 && i <= 25))//輸出成績優秀名單{printf("學號\t姓名\t班級\t數學\t英語\t政治\t體育\t物理\t總分\t平均分\n");while (pcur != NULL){flag = 1;switch (i){case 11:if (pcur->math < 60)printOneNoHead(*pcur); break;case 12:if (pcur->english < 60)printOneNoHead(*pcur); break;case 13:if (pcur->politics < 60)printOneNoHead(*pcur); break;case 14:if (pcur->sports < 60)printOneNoHead(*pcur); break;case 15:if (pcur->physics < 60)printOneNoHead(*pcur); break;case 21:if (pcur->math >= 90)printOneNoHead(*pcur); break;case 22:if (pcur->english >= 90)printOneNoHead(*pcur); break;case 23:if (pcur->politics >= 90)printOneNoHead(*pcur); break;case 24:if (pcur->sports >= 90)printOneNoHead(*pcur); break;case 25:if (pcur->physics >= 90)printOneNoHead(*pcur); break;}pcur = pcur->pnext;}system("pause");}//輸出單科平均分else if (i >= 31 && i <= 35){//遍歷計算總數pcur = *pphead;//這句可能不需要int totalStu = 0;while (pcur != NULL){totalStu++;pcur = pcur->pnext;}//計算pcur = *pphead;//pcur歸位float average = 0;switch (i){case 31:printf("數學");while (pcur != NULL){average += pcur->math;pcur = pcur->pnext;}printf("平均分:%.2f", average /= totalStu);system("pause");break;case 32:printf("英語");while (pcur != NULL){average += pcur->english;pcur = pcur->pnext;}printf("平均分:%.2f", average /= totalStu);system("pause");break;case 33:printf("政治");while (pcur != NULL){average += pcur->politics;pcur = pcur->pnext;}printf("平均分:%.2f", average /= totalStu);system("pause");break;case 34:printf("體育");while (pcur != NULL){average += pcur->sports;pcur = pcur->pnext;}printf("平均分:%.2f", average /= totalStu);system("pause");break;case 35:printf("物理");while (pcur != NULL){average += pcur->physics;pcur = pcur->pnext;}printf("平均分:%.2f", average /= totalStu);system("pause");break;}}else if (i == 41){pcur = *pphead;//pcur歸位system("cls");printf("請輸入班號:\n");scanf("%d", &i);printf("學號\t姓名\t班級\t數學\t英語\t政治\t體育\t物理\t總分\t平均分\n");while (pcur != NULL){if (pcur->classnum == i){printOneNoHead(*pcur);}pcur = pcur->pnext;}system("pause");return;} }//計算總分和平均分 void AddAndAverage(pstu one) {one->total = one->english + one->math + one->physics + one->politics + one->sports;one->average = one->total / COURSENUM; } //更新總分、平均分 void update(pstu *pphead, pstu *pptail) {pstu pcur = *pphead;while (pcur != NULL){pcur->total = pcur->english + pcur->math + pcur->physics + pcur->politics + pcur->sports;pcur->average = pcur->total / COURSENUM;pcur = pcur->pnext;} } //增:有序插入 void list_insert_sort(pstu *pphead, pstu *pptail, int i) {pstu pnew;pnew = (pstu)calloc(1, sizeof(stu));pnew->id = i;printf("請輸入姓名:");scanf("%s", pnew->name); rewind(stdin);printf("請輸入班號:");scanf("%d", &pnew->classnum); rewind(stdin);pnew->math = pnew->english = pnew->politics = pnew->sports = pnew->physics = pnew->total = pnew->average = 0;pstu pcur = *pphead;pstu pbefore = *pphead;if (NULL == *pptail)//如果鏈表為空{*pphead = pnew;*pptail = pnew;}else{//從小到大if (i <= pcur->id)//如果小于第一個節點,頭插{pnew->pnext = *pphead;//新節點的pnext成員指向原有鏈表頭*pphead = pnew;//新節點成為新的鏈表頭return;}else//向后遍歷{while (NULL != pcur)//只要不是最后{if (i <= pcur->id){pbefore->pnext = pnew;//小弟的pnext成員指向新節點pnew->pnext = pcur;//新節點的pnext成員指向大哥break;}pbefore = pcur;//小弟記住大哥的腳印pcur = pcur->pnext;//大哥先走一步 }if (NULL == pcur)//如果到最后,尾插{(*pptail)->pnext = pnew;//原有鏈表尾的pnext成員指向新節點*pptail = pnew;//新節點成為新的鏈表尾}}} }//刪除 void list_delete(pstu *pphead, pstu *pptail, int i) {pstu pcur = *pphead;pstu pbefore = *pphead;if (NULL == *pptail)//如果鏈表為空{printf("鏈表為空\n");}else if (i == (*pphead)->id)//如果等于第一個節點(此時可能僅剩一個節點){*pphead = (*pphead)->pnext;//頭指針指向下一個節點if (NULL == *pphead){*pptail = NULL;free(pcur);}}else//如果不等于第一個節點{while (NULL != pcur)//只要不是最后{if (i == pcur->id)//如果等于當前節點{pcur = pcur->pnext;//大哥前進一步pbefore->pnext = pcur;//小弟的pnext成員指向大哥return;}else{pbefore = pcur;//小弟記住大哥的腳印pcur = pcur->pnext;//大哥先走一步 }}if (NULL == pcur)//如果到最后{printf("不存在此學號\n");}} }//修改 void list_modify(pstu *pphead, pstu *pptail, int i) {int score;pstu pcur = *pphead;pstu pbefore = *pphead;if (NULL == *pptail)//如果鏈表為空{printf("鏈表為空\n");}else{while (NULL != pcur)//只要不是最后{if (i == pcur->id)//如果等于當前節點,修改{int sub;printOne(*pcur);while (printf("請選擇科目(輸入科目代號):1高數 2英語 3政治 4體育 5物理\n")){if (scanf("%d", &sub) == EOF){rewind(stdin);return;}printf("請輸入分數:");scanf("%d", &score);switch (sub){case 1:pcur->math = score; AddAndAverage(pcur); printOne(*pcur); break;case 2:pcur->english = score; AddAndAverage(pcur); printOne(*pcur); break;case 3:pcur->politics = score; AddAndAverage(pcur); printOne(*pcur); break;case 4:pcur->sports = score; AddAndAverage(pcur); printOne(*pcur); break;case 5:pcur->physics = score; AddAndAverage(pcur); printOne(*pcur); break;}}}else{pbefore = pcur;//小弟記住大哥的腳印pcur = pcur->pnext;//大哥先走一步 }}if (NULL == pcur)//如果到最后{printf("不存在此學號\n");}} } //查找 void list_find(pstu *pphead, pstu *pptail, int i) {pstu pcur = *pphead;pstu pbefore = *pphead;if (NULL == *pptail)//如果鏈表為空{printf("鏈表為空\n");system("pause");}else{while (NULL != pcur)//只要不是最后{if (i == pcur->id)//如果等于當前節點,輸出{printOne(*pcur);system("pause");return;}else{pbefore = pcur;//小弟記住大哥的腳印pcur = pcur->pnext;//大哥先走一步 }}if (NULL == pcur)//如果到最后{printf("不存在此數字\n");}} }

sort.c

#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include"head.h"//按總分 選擇排序 void arr_select(pstu *pphead, pstu *pptail, int subject)//sunject排序依據 1總分 2數學 3英語 4政治 5體育 6物理 {int t;pstu temp = (pstu)calloc(1, sizeof(stu));//這里不能強行將temp賦給任何(無意義的)變量,必須申請新的空間。否則temp的值會在swap的時候漂移pstu pleft = *pphead;pstu pright = *pphead;pstu prightmax = NULL;if (NULL == *pptail)//如果鏈表為空{printf("鏈表為空\n");system("pause");}else{for (; pleft != NULL; pleft = pleft->pnext)//最大的數放在左邊{pright = pleft;for (prightmax = pright; pright != NULL; pright = pright->pnext)//從右邊找出最大的數,用prightmax記錄其位置{switch (subject){case 1:if (pright->total > prightmax->total){prightmax = pright;}break;case 2:if (pright->math > prightmax->math){prightmax = pright;}break;case 3:if (pright->english > prightmax->english){prightmax = pright;}break;case 4:if (pright->politics > prightmax->politics){prightmax = pright;}break;case 5:if (pright->sports > prightmax->sports){prightmax = pright;}break;case 6:if (pright->physics > prightmax->physics){prightmax = pright;}break;case 7:if (pright->id < prightmax->id){prightmax = pright;}break;}}//SWAP(*pleft, *prightmax)(*temp).id = pleft->id;for (t = 0; t < 20; t++)//迷之復制字符串{(*temp).name[t] = pleft->name[t];}(*temp).classnum = pleft->classnum;(*temp).math = pleft->math;(*temp).english = pleft->english;(*temp).politics = pleft->politics;(*temp).sports = pleft->sports;(*temp).physics = pleft->physics;(*temp).total = pleft->total;(*temp).average = pleft->average;pleft->id = prightmax->id;for (t = 0; t < 20; t++)//迷之復制字符串{pleft->name[t] = prightmax->name[t];}pleft->classnum = prightmax->classnum;pleft->math = prightmax->math;pleft->english = prightmax->english;pleft->politics = prightmax->politics;pleft->sports = prightmax->sports;pleft->physics = prightmax->physics;pleft->total = prightmax->total;pleft->average = prightmax->average;prightmax->id = (*temp).id;for (t = 0; t < 20; t++)//迷之復制字符串{prightmax->name[t] = (*temp).name[t];}prightmax->classnum = (*temp).classnum;prightmax->math = (*temp).math;prightmax->english = (*temp).english;prightmax->politics = (*temp).politics;prightmax->sports = (*temp).sports;prightmax->physics = (*temp).physics;prightmax->total = (*temp).total;prightmax->average = (*temp).average;}} }

read.c

#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include"head.h"void readData(pstu *pphead, pstu *pptail) {int TOTAL;pstu pcur = *pphead;pstu pbefore = *pphead;pstu pnew;FILE *fpReadAgain = fopen("data.txt", "r");//讀取fscanf(fpReadAgain, "%d", &TOTAL);for (int j = 0; j < TOTAL; j++){pcur = *pphead;pbefore = *pphead;pnew = (pstu)calloc(1, sizeof(stu));//只申請一個fscanf(fpReadAgain, "%d %s %d %d %d %d %d %d %d %d", &pnew->id, &pnew->name, &pnew->classnum, &pnew->math, &pnew->english, &pnew->politics, &pnew->sports, &pnew->physics, &pnew->total, &pnew->average);if (NULL == *pptail)//如果鏈表為空{*pphead = pnew;*pptail = pnew;//不用擔心尾節點不是NULL,因為calloc的pnew中的pnext成員本身就是null}else{(*pptail)->pnext = pnew;//原有鏈表尾的pnext成員指向新節點*pptail = pnew;//新節點成為新的鏈表尾}}fclose(fpReadAgain); }

write.c

#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include"head.h" void writeData(pstu *pphead, pstu *pptail) {int TOTAL = 0;//計算鏈表長度pstu pcur = *pphead;while (pcur != NULL){TOTAL++;pcur = pcur->pnext;}FILE *fpPrintAgain = fopen("data.txt", "w");//輸出fprintf(fpPrintAgain, "%d\n", TOTAL);//輸出總數據量,便于下一次讀取pcur = *pphead;while (pcur != NULL){fprintf(fpPrintAgain, "%d %s %d %d %d %d %d %d %d %d\n", pcur->id, pcur->name, pcur->classnum, pcur->math, pcur->english, pcur->politics, pcur->sports, pcur->physics, pcur->total, pcur->average);pcur = pcur->pnext;}fclose(fpPrintAgain); }

總結

以上是生活随笔為你收集整理的C语言课设 成绩管理程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。