C语言课设 成绩管理程序
生活随笔
收集整理的這篇文章主要介紹了
C语言课设 成绩管理程序
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
成績(jī)管理程序
功能:
(1) 錄入若干個(gè)學(xué)生每門(mén)課程的分?jǐn)?shù);
(2) 給定學(xué)號(hào),顯示某位學(xué)生所有課程成績(jī);
(3) 給定某個(gè)班級(jí)的班號(hào),顯示該班所有學(xué)生的課程成績(jī)情況;
(4) 給定學(xué)號(hào),修改該學(xué)生的課程成績(jī)信息;
(5) 按照某門(mén)課程的成績(jī)從高到低排序;
(6) 提供一些統(tǒng)計(jì)各類信息的功能(例如,某門(mén)課程不及格名單、某門(mén)課程的總平均成績(jī)等)
關(guān)于本程序
- 連續(xù)按三次ctrl z可以返回上一級(jí)菜單
- 請(qǐng)按照正常順序,一級(jí)一級(jí)退出,不要直接點(diǎn)擊右上角關(guān)閉程序。否則,data.txt可能沒(méi)有完全寫(xiě)入
- 想即時(shí)保存也行,每次操作完成之后加一句writeData(&phead, &ptail);即可
- 你可以直接在txt中進(jìn)行修改成績(jī)操作,且不必輸入總分、平均分,但一定要保證:格式正確
txt存儲(chǔ)格式如下
- 總?cè)藬?shù)
- 學(xué)號(hào) 姓名 班級(jí) 數(shù)學(xué) 英語(yǔ) 政治 體育 物理 總分 平均分
程序文件構(gòu)成 (見(jiàn)左側(cè)解決方案資源管理器)
運(yùn)行環(huán)境:vs2017
以下為全部代碼
main.c
/* ===================================成績(jī)管理程序===================================* 注意:* 連續(xù)按三次ctrl z可以返回上一級(jí)菜單* 請(qǐng)按照正常順序,一級(jí)一級(jí)退出,不要直接點(diǎn)擊右上角關(guān)閉程序。否則,data.txt可能沒(méi)有完全寫(xiě)入* 想即時(shí)保存也行,每次操作完成之后加一句writeData(&phead, &ptail);即可* 你可以直接在txt中進(jìn)行修改成績(jī)操作,且不必輸入總分、平均分,但一定要保證:格式正確** txt存儲(chǔ)格式如下:* 總?cè)藬?shù)* 學(xué)號(hào) 姓名 班級(jí) 數(shù)學(xué) 英語(yǔ) 政治 體育 物理 總分 平均分*==================================================================================*/#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);//更新數(shù)據(jù)(若用戶直接操作txt文件,該函數(shù)可以自動(dòng)計(jì)算新的總分、平均分)update(&phead, &ptail);//選擇想要的操作int choose;while (printHome(), printf("\n請(qǐng)輸入你選擇的操作:"), scanf("%d", &choose) != EOF){rewind(stdin);system("cls");switch (choose){case 1://增while (system("cls"), list_print(phead, ptail), printf("(三次ctrl z返回上一級(jí))\n請(qǐng)輸入要添加的學(xué)號(hào):"), 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返回上一級(jí))\n請(qǐng)輸入刪除的學(xué)號(hào):"), 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返回上一級(jí))\n請(qǐng)輸入修改的學(xué)號(hào):"), scanf("%d", &i) != EOF){rewind(stdin);list_modify(&phead, &ptail, i);}writeData(&phead, &ptail);break;case 4://查while (system("cls"), printf("(三次ctrl z返回上一級(jí))\n請(qǐng)輸入查找的學(xué)號(hào):"), scanf("%d", &i) != EOF){rewind(stdin);list_find(&phead, &ptail, i);}writeData(&phead, &ptail);break;case 5://排序while (system("cls"), printf("(三次ctrl z返回上一級(jí))\n請(qǐng)輸入排序依據(jù):\n1總分 2數(shù)學(xué) 3英語(yǔ) 4政治 5體育 6物理 7學(xué)號(hào)\n"), scanf("%d", &i) != EOF){rewind(stdin);arr_select(&phead, &ptail, i);list_print(phead, ptail);system("pause");}writeData(&phead, &ptail);break;case 6://統(tǒng)計(jì)信息while (system("cls"), printf("(三次ctrl z返回上一級(jí))\n請(qǐng)輸入要查看的數(shù)據(jù)編號(hào):\n(一)不及格名單(小于60分)\n11 數(shù)學(xué)\n12 英語(yǔ)\n13 政治\n14 體育\n15 物理\n\n(二) 成績(jī)優(yōu)秀名單(大于90分)\n21 數(shù)學(xué)\n22 英語(yǔ)\n23 政治\n24 體育\n25 物理\n\n(三) 課程平均成績(jī)\n31 數(shù)學(xué)\n32 英語(yǔ)\n33 政治\n34 體育\n35 物理\n\n(四) 按班級(jí)分類\n41 輸出某個(gè)班的成績(jī)\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; #endiflist.c
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include"head.h" //打印首頁(yè) void printHome() {system("cls");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * *\n");printf(" * 學(xué) 生 成 績(jī) 管 理 系 統(tǒng) *\n");printf(" * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * *\n");printf(" * * 1.添 加 學(xué) 生 * 2.刪 除 學(xué) 生 *\n");printf(" * 功 * * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");printf(" * 能 * * *\n");printf(" * * 3.修 改 成 績(jī) * 4.查 找 學(xué) 生 *\n");printf(" * 菜 * * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");printf(" * 單 * * *\n");printf(" * * 5.按 要 求 排 序 * 6.統(tǒng) 計(jì) 信 息 *\n");printf(" * * * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * *\n");printf(" * 提 示 :任 意 界 面 下 , 連 續(xù) 三 次 ctrl z 返 回 上 一 級(jí) *\n");printf(" * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");}//打印總表 void list_print(pstu phead, pstu ptail) {int flag = 0;pstu pcur = phead;printf("學(xué)號(hào)\t姓名\t班級(jí)\t數(shù)學(xué)\t英語(yǔ)\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");//空表時(shí)不打印換行 }//打印當(dāng)前學(xué)生 void printOne(stu one) {printf("學(xué)號(hào)\t姓名\t班級(jí)\t數(shù)學(xué)\t英語(yǔ)\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); } //打印統(tǒng)計(jì)信息 void statistics(pstu *pphead, pstu *pptail, int i) {int flag = 0;pstu pcur = *pphead;if ((i >= 11 && i <= 15) || (i >= 21 && i <= 25))//輸出成績(jī)優(yōu)秀名單{printf("學(xué)號(hào)\t姓名\t班級(jí)\t數(shù)學(xué)\t英語(yǔ)\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){//遍歷計(jì)算總數(shù)pcur = *pphead;//這句可能不需要int totalStu = 0;while (pcur != NULL){totalStu++;pcur = pcur->pnext;}//計(jì)算pcur = *pphead;//pcur歸位float average = 0;switch (i){case 31:printf("數(shù)學(xué)");while (pcur != NULL){average += pcur->math;pcur = pcur->pnext;}printf("平均分:%.2f", average /= totalStu);system("pause");break;case 32:printf("英語(yǔ)");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("請(qǐng)輸入班號(hào):\n");scanf("%d", &i);printf("學(xué)號(hào)\t姓名\t班級(jí)\t數(shù)學(xué)\t英語(yǔ)\t政治\t體育\t物理\t總分\t平均分\n");while (pcur != NULL){if (pcur->classnum == i){printOneNoHead(*pcur);}pcur = pcur->pnext;}system("pause");return;} }//計(jì)算總分和平均分 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("請(qǐng)輸入姓名:");scanf("%s", pnew->name); rewind(stdin);printf("請(qǐng)輸入班號(hào):");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)//如果小于第一個(gè)節(jié)點(diǎn),頭插{pnew->pnext = *pphead;//新節(jié)點(diǎn)的pnext成員指向原有鏈表頭*pphead = pnew;//新節(jié)點(diǎn)成為新的鏈表頭return;}else//向后遍歷{while (NULL != pcur)//只要不是最后{if (i <= pcur->id){pbefore->pnext = pnew;//小弟的pnext成員指向新節(jié)點(diǎn)pnew->pnext = pcur;//新節(jié)點(diǎn)的pnext成員指向大哥break;}pbefore = pcur;//小弟記住大哥的腳印pcur = pcur->pnext;//大哥先走一步 }if (NULL == pcur)//如果到最后,尾插{(*pptail)->pnext = pnew;//原有鏈表尾的pnext成員指向新節(jié)點(diǎn)*pptail = pnew;//新節(jié)點(diǎn)成為新的鏈表尾}}} }//刪除 void list_delete(pstu *pphead, pstu *pptail, int i) {pstu pcur = *pphead;pstu pbefore = *pphead;if (NULL == *pptail)//如果鏈表為空{printf("鏈表為空\(chéng)n");}else if (i == (*pphead)->id)//如果等于第一個(gè)節(jié)點(diǎn)(此時(shí)可能僅剩一個(gè)節(jié)點(diǎn)){*pphead = (*pphead)->pnext;//頭指針指向下一個(gè)節(jié)點(diǎn)if (NULL == *pphead){*pptail = NULL;free(pcur);}}else//如果不等于第一個(gè)節(jié)點(diǎn){while (NULL != pcur)//只要不是最后{if (i == pcur->id)//如果等于當(dāng)前節(jié)點(diǎn){pcur = pcur->pnext;//大哥前進(jìn)一步pbefore->pnext = pcur;//小弟的pnext成員指向大哥return;}else{pbefore = pcur;//小弟記住大哥的腳印pcur = pcur->pnext;//大哥先走一步 }}if (NULL == pcur)//如果到最后{printf("不存在此學(xué)號(hào)\n");}} }//修改 void list_modify(pstu *pphead, pstu *pptail, int i) {int score;pstu pcur = *pphead;pstu pbefore = *pphead;if (NULL == *pptail)//如果鏈表為空{printf("鏈表為空\(chéng)n");}else{while (NULL != pcur)//只要不是最后{if (i == pcur->id)//如果等于當(dāng)前節(jié)點(diǎn),修改{int sub;printOne(*pcur);while (printf("請(qǐng)選擇科目(輸入科目代號(hào)):1高數(shù) 2英語(yǔ) 3政治 4體育 5物理\n")){if (scanf("%d", &sub) == EOF){rewind(stdin);return;}printf("請(qǐng)輸入分?jǐn)?shù):");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("不存在此學(xué)號(hào)\n");}} } //查找 void list_find(pstu *pphead, pstu *pptail, int i) {pstu pcur = *pphead;pstu pbefore = *pphead;if (NULL == *pptail)//如果鏈表為空{printf("鏈表為空\(chéng)n");system("pause");}else{while (NULL != pcur)//只要不是最后{if (i == pcur->id)//如果等于當(dāng)前節(jié)點(diǎn),輸出{printOne(*pcur);system("pause");return;}else{pbefore = pcur;//小弟記住大哥的腳印pcur = pcur->pnext;//大哥先走一步 }}if (NULL == pcur)//如果到最后{printf("不存在此數(shù)字\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排序依據(jù) 1總分 2數(shù)學(xué) 3英語(yǔ) 4政治 5體育 6物理 {int t;pstu temp = (pstu)calloc(1, sizeof(stu));//這里不能強(qiáng)行將temp賦給任何(無(wú)意義的)變量,必須申請(qǐng)新的空間。否則temp的值會(huì)在swap的時(shí)候漂移pstu pleft = *pphead;pstu pright = *pphead;pstu prightmax = NULL;if (NULL == *pptail)//如果鏈表為空{printf("鏈表為空\(chéng)n");system("pause");}else{for (; pleft != NULL; pleft = pleft->pnext)//最大的數(shù)放在左邊{pright = pleft;for (prightmax = pright; pright != NULL; pright = pright->pnext)//從右邊找出最大的數(shù),用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++)//迷之復(fù)制字符串{(*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++)//迷之復(fù)制字符串{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++)//迷之復(fù)制字符串{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));//只申請(qǐng)一個(gè)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;//不用擔(dān)心尾節(jié)點(diǎn)不是NULL,因?yàn)閏alloc的pnew中的pnext成員本身就是null}else{(*pptail)->pnext = pnew;//原有鏈表尾的pnext成員指向新節(jié)點(diǎn)*pptail = pnew;//新節(jié)點(diǎn)成為新的鏈表尾}}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;//計(jì)算鏈表長(zhǎng)度pstu pcur = *pphead;while (pcur != NULL){TOTAL++;pcur = pcur->pnext;}FILE *fpPrintAgain = fopen("data.txt", "w");//輸出fprintf(fpPrintAgain, "%d\n", TOTAL);//輸出總數(shù)據(jù)量,便于下一次讀取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); }總結(jié)
以上是生活随笔為你收集整理的C语言课设 成绩管理程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: C++ 算法设计 最大子序和问题
- 下一篇: 牛客网_PAT乙级_1027在霍格沃茨找