C语言 课设 最新版 学生成绩管理系统
生活随笔
收集整理的這篇文章主要介紹了
C语言 课设 最新版 学生成绩管理系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
運行效果
main.cpp
/* ===================================成績管理程序===================================* 注意:* 連續按三次ctrl z可以返回上一級菜單* 請按照正常順序,一級一級退出,不要直接點擊右上角關閉程序。否則,data.txt可能沒有完全寫入* 想即時保存也行,每次操作完成之后加一句writeData(&phead, &ptail);即可* 你可以直接在txt中進行修改成績操作,且不必輸入總分、平均分,但一定要保證:格式正確** txt存儲格式如下:* 總人數* 學號 姓名 班級 數學 英語 政治 體育 物理 總分 平均分** 新增功能:* 1、首頁動態效果* 2、模式選擇功能【學生模式、教師模式、開發者模式】模式不同,權限不同。* 開發者具有所有權限,可自動生成學號不重復的學生及成績,方便做測試使用。* 模式選擇菜單下,如果輸入數字非法,則默認無任何權限。*==================================================================================*/#include"list.c" #include"sort.c" #include"read.c" #include"write.c" int main() {srand((int)time(NULL));//產生隨機數的種子 int i;pstu phead = NULL;pstu ptail = NULL;readData(&phead, &ptail);//更新數據(若用戶直接操作txt文件,該函數可以自動計算新的總分、平均分)update(&phead, &ptail);//選擇模式int mode;bool valid[7] = { false };label1:mode = chooseMode();switch (mode){ case 1:valid[0] = false; valid[1] = false; valid[2] = false; valid[3] = true; valid[4] = true; valid[5] = true; valid[6] = false; break;case 2:valid[0] = true; valid[1] = true; valid[2] = true; valid[3] = true; valid[4] = true; valid[5] = true; valid[6] = false; break;case 3:valid[0] = true; valid[1] = true; valid[2] = true; valid[3] = true; valid[4] = true; valid[5] = true; valid[6] = true; break;}//選擇操作int choose;while (printHome(), printf("\n請輸入你選擇的操作:"), scanf("%d", &choose) != EOF){rewind(stdin);//判斷當前模式下權限system("cls");switch (valid[choose - 1]){case true:break;case false:{printf("對不起,當前模式下您沒有訪問權限,請切換模式!");system("pause");goto label1;}}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學號 8班級\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;case 7://自動生成while (system("cls"), printf("(三次ctrl z返回上一級)\n請輸入生成學生的數量:"), scanf("%d", &i) != EOF){rewind(stdin);newStu(&phead, &ptail, i);printf("生成成功!\n");list_print(phead, ptail);system("pause");}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<time.h> #include<conio.h> #include <windows.h> #include"head.h" #define TIME 600 //打印首頁 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(" * * 7.( 高 級 模 式 ) 自 動 生 成 學 生 及 分 數 *\n");printf(" * * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * *\n");printf(" * 提 示 :任 意 界 面 下 , 連 續 三 次 ctrl z 返 回 上 一 級 *\n");printf(" * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n"); }//選擇模式 int chooseMode() {srand((int)time(NULL));//產生隨機數的種子 char exitflag = '\0';for (int i = 1; ; i++){Sleep(TIME);system("cls");{printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * **\n");printf(" * * 歡 迎 使 用 學 生 成 績 管 理 系 統 ! **\n");printf(" * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * *\n");printf(" * 按 任 意 鍵 繼 續 *\n");printf(" * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");if (_kbhit()){//函數名: getch()//功能及返回值 : 從鍵盤上讀取到的字符exitflag = _getch();if (exitflag){break;}}Sleep(TIME);system("cls");{printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * **\n");printf(" * * 歡 迎 使 用 學 生 成 績 管 理 系 統 ! **\n");printf(" * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * *\n");printf(" * *\n");printf(" * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");}}}system("cls");int mode;printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * *\n");printf(" * 學 生 成 績 管 理 系 統 *\n");printf(" * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * *\n");printf(" * * 1. 我 是 學 生 *\n");printf(" * 選 * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");printf(" * * *\n");printf(" * 則 * 2. 我 是 教 師 *\n");printf(" * * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");printf(" * 模 * *\n");printf(" * * 3. 我 是 開 發 者 *\n");printf(" * * *\n");printf(" * 式 ** * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * * <權 限 說 明>:學 生 只 能 查 看 成 績 *\n");printf(" * * 教 師 幾 乎 擁 有 所 有 權 限 , 如: 修 改 成 績 *\n");printf(" * * 開 發 者 擁 有 最 高 權 限 ,可 自 動 生 成 學 生 *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf(" * *\n");printf(" * 提 示 :任 意 界 面 下 , 連 續 三 次 ctrl z 返 回 上 一 級 *\n");printf(" * *\n");printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **\n");printf("請選擇模式:\n");scanf("%d", &mode);return mode; }//打印總表 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");}} }//自動生成一個學生 int rand_number()//生成成績 {int num;num = rand() % 50 + 50;return num; } int rand_id(pstu phead, pstu ptail)//生成學號 {int num; label2:num = rand() % 199 + 1;pstu pcur = phead;while (pcur != NULL){if (pcur->id == num){goto label2;}pcur = pcur->pnext;}return num; } void newStu(pstu *pphead, pstu *pptail, int i) {int num;for (; i > 0; i--){pstu pnew;pnew = (pstu)calloc(1, sizeof(stu));num = rand_id(*pphead, *pptail);pnew->id = num;pnew->name[0] = 'a';//迷之字符串賦值pnew->name[1] = 'u';pnew->name[2] = 't';pnew->name[3] = 'o';pnew->name[4] = 0;num = rand_number();pnew->classnum = num % 9 + 1;num = rand_number();pnew->math = num;num = rand_number();pnew->english = num;num = rand_number();pnew->politics = num;num = rand_number();pnew->sports = num;num = rand_number();pnew->physics = num;pnew->total = pnew->english + pnew->math + pnew->physics + pnew->politics + pnew->sports;pnew->average = pnew->total / COURSENUM;//頭插法if (NULL == *pptail){*pphead = pnew;*pptail = pnew;}else{(*pptail)->pnext = pnew;*pptail = pnew;}} }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物理 7學號 8班級 {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;case 8:if (pright->classnum < prightmax->classnum){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语言 课设 最新版 学生成绩管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于vector的迭代器失效的问题
- 下一篇: PAT1005 继续(3n+1)猜想 (