運行效果
?
D:wangcCLionProjects est1212cmake-build-debug est1212.exe ????????????????????????????????????????????????【學(xué)生管理系統(tǒng)2.0】 ????????????????★————————————————————————————————————————★ ???????????????????????????|?1.?信息錄入????????????????2.?成績錄入?????????????3.?信息查詢??| ???????????????????????????|?4.?成績查詢????????????????5.?刪除信息?????????????6.?信息追加??| ???????????????????????????|?7.?更改分數(shù)????????????????8.?查看排名?????????????9.?成績分段??| ???????????????????????????|?10.保存文件????????????????11.文件輸出?????????????12.文件導(dǎo)入??| ????????????????★————————————————按0并回車退出——————————————————★ 請輸入執(zhí)行數(shù)字:1 *****************************************************信息錄入*********************************************************** 依次鍵入學(xué)號、姓名、性別、宿舍號碼、電話號碼,用一個【空格】隔開各數(shù)據(jù),每一條輸入完成后按回車鍵進行下一條輸入。 ?????????????????????????????????????????????【退出請輸入'0'并回車】 樣例: 541913460230?張三?男?1717?66666 在此輸入: 1001?張三豐?男?521?888888 1001?張三豐?男?521?888888 1002?李四?男?522?555555 1002?李四?男?522?555555 0 0 請輸入執(zhí)行數(shù)字:3 請在此輸入:1002 1002 輸入了錯誤的第一次選擇數(shù)字!重新輸入: 3 3 輸入了錯誤的第一次選擇數(shù)字!重新輸入: 0 0 輸入了錯誤的第一次選擇數(shù)字!重新輸入: 1 1 通過學(xué)號(輸入1),姓名(輸入2):1 1 輸入學(xué)號(輸入0并回車結(jié)束):1001 1001 學(xué)號:1001?姓名:張三豐?性別:男?宿舍號碼:521?電話號碼:888888 輸入學(xué)號(輸入0并回車結(jié)束):
?
源碼
?
#include#include #include #include #define?LEN?sizeof(struct?student) struct?student { ????char?num[20];//學(xué)號 ????char?name[20];//姓名 ????char?sex[20];//性別 ????char?room[20];//宿舍號碼 ????char?tel[20];//電話號碼 ????char?CHN[20];//語文 ????char?MATH[20];//數(shù)學(xué) ????char?ENG[20];//英語 ????char?PE[20];//體育 ????char?PRO[20];//專業(yè) ????char?average_score[20];//平均分 ????struct?student?*next; }; int?n;//節(jié)點數(shù) struct?student?*creat();//信息錄入 void?score(struct?student?*head);//成績錄入 void?findinformation(struct?student?*head);//信息查詢 void?findscore(struct?student?*head);//成績查詢 struct?student?*del(struct?student?*head);//信息刪除 struct?student?*insert(struct?student?*head);//信息插入 void?update(struct?student?*head);//修改分數(shù) void?Oscore(struct?student*head);//排序輸出 void?swap(struct?student*p1,struct?student*p2);//交換數(shù)據(jù) void?fenduan(struct?student*head);//分段輸出 int?checknum(char?ch[]);//檢查純數(shù)字的數(shù)據(jù)里是否混入了非數(shù)字的非法輸入 int?transformint(char?ch[]);//純數(shù)字整數(shù)(字符串轉(zhuǎn)向int類型) void?save(struct?student?*head);?//文件存儲 void?export1();//文件輸出 struct?student?*import();//文件導(dǎo)入 int?checkscore(char?ch[]);//檢查分數(shù)是否為0-99的純數(shù)字 int?IncludeChinese(char?*str);?//檢查性名、性別是否包含漢字 int?main() { ????//微信關(guān)注公眾號:C語言中文社區(qū),免費領(lǐng)取更多 ????struct?student?*head=NULL; ????char?choose[20]; ????menu://設(shè)置主菜單的點 ????printf(" "); ????printf(" 【學(xué)生管理系統(tǒng)2.0】 "); ????printf(" ★————————————————————————————————————————★ "); ????printf(" ???|?1.?信息錄入 2.?成績錄入 3.?信息查詢??| "); ????printf(" ???|?4.?成績查詢 5.?刪除信息 6.?信息追加??| "); ????printf(" ???|?7.?更改分數(shù) 8.?查看排名 9.?成績分段??| "); ????printf(" ???|?10.保存文件 11.文件輸出 12.文件導(dǎo)入??| "); ????printf(" ★————————————————按0并回車退出——————————————————★ "); ????printf("請輸入執(zhí)行數(shù)字:"); ????while(scanf("%s",choose)&&checknum(choose)==0)//檢查到不是純數(shù)字?讓用戶重新輸入 ????{ ????????printf("輸入無效,重新輸入:"); ????} ????switch(transformint(choose)) ????{ ????????case?1: ????????????head=creat(); ????????????break; ????????case?2: ????????????score(head); ????????????break; ????????case?3: ????????????findinformation(head); ????????????break; ????????case?4: ????????????findscore(head); ????????????break; ????????case?5: ????????????head=del(head); ????????????break; ????????case?6: ????????????head=insert(head); ????????????break; ????????case?7: ????????????update(head); ????????????break; ????????case?8: ????????????Oscore(head); ????????????break; ????????case?9: ????????????fenduan(head); ????????????break; ????????case?10: ????????????save(head); ????????????break; ????????case?11: ????????????export1(); ????????????break; ????????case?12: ????????????head=import(); ????????????break; ????} ????if(transformint(choose)<0||transformint(choose)>12)//輸入了不在執(zhí)行數(shù)字范圍內(nèi)的數(shù)字返回主菜單的點 ????{ ????????system("cls");//清理屏幕和緩沖區(qū) ????????fflush(stdin); ????????goto?menu; ????} ????if(transformint(choose)!=0)//輸入不是0,繼續(xù)回到主菜單 ????{ ????????goto?menu; ????} ????system("cls");//結(jié)束時清理屏幕和緩沖區(qū),打印下方的校徽 ????fflush(stdin); ????printf(" 感謝使用! "); ????printf(" ?????????????????????????????????????????????????????* "); ????printf("????????????????????????????????????????????????*??***??**** "); ????printf("??????????????????????????????????????????????***?****?**** "); ????printf("?????????????????????????????????????????????****?****?****?**** "); ????printf("?????????????????????????????????????????????****?****?****?**** "); ????printf("?????????????????????????????????????????????****?****?****?**** "); ????printf("?????????????????????????????????????????????****?****?****?**** "); ????printf("?????????????????????????????????????????????****?****?****?**** "); ????printf("??????????????????????????????????????????????****?*******?**** "); ????printf("????????????????????????????????????????????????************* "); ????printf("????????????????????????????????????????????????????***** "); ????system("pause"); ????return?0; } struct?student?*creat()//錄入信息,創(chuàng)建鏈表 { ????system("cls"); ????fflush(stdin); ????printf("*****************************************************信息錄入*********************************************************** "); ????printf("依次鍵入學(xué)號、姓名、性別、宿舍號碼、電話號碼,用一個【空格】隔開各數(shù)據(jù),每一條輸入完成后按回車鍵進行下一條輸入。????????? "); ????printf("?????????????????????????????????????????????【退出請輸入'0'并回車】????????????????????????????????????????????????????? "); ????printf("樣例: 541913460230?張三?男?1717?66666 在此輸入: "); ????n=0; ????struct?student?*head,*p1,*p2; ????head?=?NULL; ????p1=p2=(struct?student*)malloc(LEN); ????while(scanf("%s",p1->num)&&checknum(p1->num)==0) ????{ ????????printf("輸入錯誤的學(xué)號,重新輸入: "); ????} ????if(transformint(p1->num)==0)//輸入了0退出函數(shù)調(diào)用,傳回去表頭指針head給主函數(shù)的head ????{ ????????system("cls"); ????????fflush(stdin); ????????return(head); ????} ????while(scanf("%s",p1->name)&&IncludeChinese(p1->name)==0)//這幾行while(scanf)都是具有容錯的輸入,整個程序中都存在輸入容錯?。?! ????{ ????????printf("輸入錯誤的名字,重新輸入: "); ????} ????while(scanf("%s",p1->sex)&&IncludeChinese(p1->sex)==0) ????{ ????????printf("輸入錯誤的性別,重新輸入: "); ????} ????while(scanf("%s",p1->room)&&checknum(p1->room)==0) ????{ ????????printf("輸入錯誤的宿舍號碼,重新輸入: "); ????} ????while(scanf("%s",p1->tel)&&checknum(p1->tel)==0) ????{ ????????printf("輸入錯誤的手機號碼,重新輸入: "); ????} ????printf(" "); ????while(transformint(p1->num)!=0)//輸入每個節(jié)點的學(xué)號不是0的時候開始循環(huán)。 ????{ ????????n+=1;//節(jié)點+1 ????????if(n==1)????//PS:此處為建立鏈表常規(guī)過程(參考了譚浩強C程序設(shè)計第九章鏈表,紅皮那本) ????????{ ????????????head=p1;//第一個節(jié)點?表頭指向上面開辟的第一個節(jié)點?p1?p2?head都指向此處此時 ????????}else ????????{ ????????????p2->next=p1;//后面的節(jié)點,p2的next指向p1將兩個節(jié)點連接到一起 ????????????p2=p1;//p2再跟p1 ????????} ????????p1=(struct?student*)malloc(LEN);//p1指向開辟的新節(jié)點 ????????while(scanf("%s",p1->num)&&checknum(p1->num)==0) ????????{ ????????????printf("輸入錯誤的學(xué)號,重新輸入: "); ????????} ????????if(transformint(p1->num)==0) ????????{ ????????????break; ????????} ????????while(scanf("%s",p1->name)&&IncludeChinese(p1->name)==0) ????????{ ????????????printf("輸入錯誤的名字,重新輸入: "); ????????} ????????while(scanf("%s",p1->sex)&&IncludeChinese(p1->sex)==0) ????????{ ????????????printf("輸入錯誤的性別,重新輸入: "); ????????} ????????while(scanf("%s",p1->room)&&checknum(p1->room)==0) ????????{ ????????????printf("輸入錯誤的宿舍號碼,重新輸入: "); ????????} ????????while(scanf("%s",p1->tel)&&checknum(p1->tel)==0) ????????{ ????????????printf("輸入錯誤的手機號碼,重新輸入: "); ????????} ????????printf(" "); ????} ????p2->next=NULL;//最后p1開辟的新節(jié)點丟棄了,讓p2的next指向空,形成表尾結(jié)束鏈表。?錄入結(jié)束 ????system("cls"); ????fflush(stdin); ????return(head); } void?score(struct?student?*head)//拿到鏈表,錄入成績 { ????system("cls"); ????fflush(stdin); ????printf("*****************************************************成績錄入*********************************************************** "); ????printf("依次鍵入語文、數(shù)學(xué)、英語、體育、專業(yè)成績,用一個空格隔開各數(shù)據(jù),每一條輸入完成后按回車鍵進行下一條輸入。 "); ????printf("??????????????????????????????????????????????【錄完分數(shù)后自動退出】?????????????????????????????????????????????????????? "); ????printf("例如: 10?20?30?40?50 在此輸入: "); ????int?Aver;//平均分 ????struct?student?*p; ????for(p=head;p!=NULL;p=p->next)//遍歷鏈表 ????{ ????????printf(" 現(xiàn)在錄入%s(%s)的成績 ",p->name,p->num); ????????while(scanf("%s",p->CHN)&&checkscore(p->CHN)==0) ????????{ ????????????printf("輸入錯誤的語文分數(shù),重新輸入: "); ????????} ????????while(scanf("%s",p->MATH)&&checkscore(p->MATH)==0) ????????{ ????????????printf("輸入錯誤的數(shù)學(xué)分數(shù),重新輸入: "); ????????} ????????while(scanf("%s",p->ENG)&&checkscore(p->ENG)==0) ????????{ ????????????printf("輸入錯誤的英語分數(shù),重新輸入: "); ????????} ????????while(scanf("%s",p->PE)&&checkscore(p->PE)==0) ????????{ ????????????printf("輸入錯誤的體育分數(shù),重新輸入: "); ????????} ????????while(scanf("%s",p->PRO)&&checkscore(p->PRO)==0) ????????{ ????????????printf("輸入錯誤的專業(yè)分數(shù),重新輸入: "); ????????} ????????Aver=(transformint(p->CHN)+transformint(p->MATH)+transformint(p->ENG)+transformint(p->PE)+transformint(p->PRO))/5; ????????itoa(Aver,p->average_score,10);//Aver十進制形式轉(zhuǎn)化為字符串存儲在鏈表的average_score平均分里 ????????printf("%s的成績錄入完了 ",p->name); ????} ????system("cls"); ????fflush(stdin); } void?findinformation(struct?student?*head)//學(xué)生信息查詢 { ????system("cls"); ????fflush(stdin); ????char?choose1[20],choose2[20];//兩個選擇的地方,choose1選擇學(xué)號/姓名?or?宿舍號?,choose2在選擇了學(xué)號/姓名時選擇?學(xué)號?or?姓名 ????char?num[20]={'1'};//用戶即將輸入的學(xué)號 ????char?name[20];//用戶即將輸入的姓名 ????char?room[20]={'1'};//用戶即將輸入的宿舍號 ????struct?student?*p; ????p=head; ????int?flag=0; ????printf("*****************************************************信息查詢*********************************************************** "); ????printf(" 選擇查找方式,學(xué)號/姓名查找(輸入1),宿舍號(輸入2) 請在此輸入:"); ????choosestation1://第一次選擇的點 ????fflush(stdin); ????while(scanf("%s",choose1)&&checknum(choose1)==0) ????{ ????????printf("輸入無效,重新輸入: "); ????} ????if(transformint(choose1)==1) ????{ ????????printf("通過學(xué)號(輸入1),姓名(輸入2):"); ????????choosestation2://第二次選擇的點 ????????fflush(stdin); ????????while(scanf("%s",choose2)&&checknum(choose2)==0) ????????{ ????????????printf("輸入無效,重新輸入: "); ????????} ????????if(transformint(choose2)==1) ????????{ ????????????while(transformint(num)!=0) ????????????{ ????????????????printf(" 輸入學(xué)號(輸入0并回車結(jié)束):"); ????????????????while(scanf("%s",num)&&checknum(num)==0) ????????????????{ ????????????????????printf("輸入錯誤的學(xué)號,重新輸入: "); ????????????????} ????????????????for(p=head;p!=NULL;p=p->next) ????????????????{ ????????????????????if(transformint(p->num)==transformint(num)) ????????????????????{ ????????????????????????printf("學(xué)號:%s?姓名:%s?性別:%s?宿舍號碼:%s?電話號碼:%s ",p->num,p->name,p->sex,p->room,p->tel); ????????????????????????flag=1; ????????????????????????break; ????????????????????} ????????????????} ????????????????if(flag==0&&transformint(num)!=0) ????????????????{ ????????????????????printf("未找到此學(xué)生信息 "); ????????????????} ????????????} ????????}else?if(transformint(choose2)==2) ????????{ ????????????while(name[0]!='#') ????????????{ ????????????????printf(" 輸入姓名(輸入#并回車結(jié)束):"); ????????????????scanf("%s",name); ????????????????for(p=head;p!=NULL;p=p->next)//遍歷鏈表 ????????????????{ ????????????????????if(strcmp(p->name,name)==0)//比較兩字符串 ????????????????????{ ????????????????????????printf("學(xué)號:%s?姓名:%s?性別:%s?宿舍號碼:%s?電話號碼:%s ",p->num,p->name,p->sex,p->room,p->tel); ????????????????????????flag=1; ????????????????????????break; ????????????????????} ????????????????} ????????????????if(flag==0&&name[0]!='#') ????????????????{ ????????????????????printf("未找到此學(xué)生信息! "); ????????????????} ????????????} ????????}else ????????{ ????????????printf("輸入了錯誤的第二次選擇數(shù)字!重新輸入: "); ????????????goto?choosestation2;//返回上面第二次選擇的點 ????????} ????}else?if(transformint(choose1)==2) ????{ ????????while(transformint(room)!=0) ????????{ ????????????printf(" 輸入宿舍號(輸入0并回車結(jié)束):"); ????????????while(scanf("%s",room)&&checknum(room)==0) ????????????{ ????????????????printf("輸入錯誤的宿舍號碼,重新輸入: "); ????????????} ????????????for(p=head;p!=NULL;p=p->next) ????????????{ ????????????????if(p->room==room) ????????????????{ ????????????????????printf("學(xué)號:%s?姓名:%s?性別:%s?宿舍號碼:%s?電話號碼:%s ",p->num,p->name,p->sex,p->room,p->tel); ????????????????????flag=1; ????????????????????break; ????????????????} ????????????} ????????????if(flag==0&&transformint(room)!=0) ????????????{ ????????????????printf("未找到此學(xué)生信息! "); ????????????} ????????} ????}else ????{ ????????printf("輸入了錯誤的第一次選擇數(shù)字!重新輸入: "); ????????goto?choosestation1;//返回最上面第一次選擇的點 ????} ????system("cls"); ????fflush(stdin); } void?findscore(struct?student?*head)//成績查詢 { ????system("cls"); ????fflush(stdin); ????char?num[20]={'1'};//初始化用戶即將輸入的學(xué)號 ????struct?student?*p; ????int?flag=0;//學(xué)號是否找到的標(biāo)志,1找到0沒找到 ????p=head; ????printf("*****************************************************成績查詢*********************************************************** "); ????printf("因為有重名的可能,暫時只能通過學(xué)號進行查詢。請輸入學(xué)號并回車進行查詢! "); ????printf("???????????????????????????????????????????????【退出請輸入'0'并回車】???????????????????????????????????????????????????? "); ????while(transformint(num)!=0) ????{ ????????printf(" 輸入學(xué)號:"); ????????while(scanf("%s",num)&&checknum(num)==0) ????????{ ????????????printf("輸入錯誤的學(xué)號,重新輸入: "); ????????} ????????for(p=head;p!=NULL;p=p->next) ????????{ ????????????if(transformint(p->num)==transformint(num)) ????????????{ ????????????????printf("學(xué)號:%s 姓名:%s 語文:%s 數(shù)學(xué):%s 英語:%s 體育:%s 專業(yè):%s ",p->num,p->name,p->CHN,p->MATH,p->ENG,p->PE,p->PRO); ????????????????flag=1; ????????????????break; ????????????} ????????} ????????if(flag==0) ????????{ ????????????printf("學(xué)號未找到! "); ????????} ????} ????system("cls"); ????fflush(stdin); } struct?student?*del(struct?student?*head)//刪除信息函數(shù) { ????system("cls"); ????fflush(stdin); ????char?num[20]={'1'};//用戶即將輸入的學(xué)號 ????struct?student?*p1,*p2; ????printf("*****************************************************信息刪除*********************************************************** "); ????if(head?==?NULL) ????{ ????????system("cls"); ????????fflush(stdin); ????????return(head); ????} ????printf(" ***************************************輸入學(xué)號進行刪除學(xué)生信息(輸入0結(jié)束)********************************************** "); ????do{ ????????printf(" 請輸入學(xué)號:"); ????????while(scanf("%s",num)&&checknum(num)==0) ????????{ ????????????printf("輸入錯誤的學(xué)號,重新輸入: "); ????????} ????????if(transformint(num)==0) ????????{ ????????????break; ????????} ????????p1=p2=head; ????????while(transformint(num)!=transformint(p1->num)&&p1->next!=NULL) ????????{ ????????????p2=p1; ????????????p1=p1->next; ????????} ????????if(transformint(num)==transformint(p1->num))//找到數(shù)字 ????????{ ????????????if(p1==head)//如果是要刪開頭的節(jié)點,直接改變表頭指向第二個節(jié)點,讓第二個節(jié)點成為新的表頭,原來的頭用free釋放掉 ????????????{ ????????????????head=p1->next; ????????????????free(p1); ????????????}else//如果刪后面的節(jié)點,要把p2連到p1所在節(jié)點后面的一個節(jié)點,將p1所在節(jié)點free釋放掉 ????????????{ ????????????????p2->next=p1->next; ????????????????free(p1); ????????????} ????????????printf("已刪除學(xué)號為%s的信息",num); ????????????n=n-1; ????????}else ????????{ ????????????printf("沒有找到學(xué)號為%s的學(xué)生 ",num); ????????} ????}while(transformint(num)!=0); ????system("cls"); ????fflush(stdin); ????return(head); } struct?student?*insert(struct?student?*head)//插入信息函數(shù) { ????system("cls"); ????fflush(stdin); ????printf("*****************************************************信息追加*********************************************************** "); ????printf("????????????????????????????????????????????【加入一組信息后自動退出】?????????????????????????????????????????????????? "); ????printf("請按照?學(xué)號?姓名?性別?宿舍號碼?電話號碼?語文?數(shù)學(xué)?英語?體育?專業(yè)?順序輸入 "); ????printf("樣例: 542013460658?李四?男?1206?10086?10?20?30?40?50 "); ????int?Aver; ????struct?student?*stud=(struct?student*)malloc(LEN);//開辟一個單元,這一塊存我們追加的信息,后面的操作把這一塊連接到鏈表的表頭 ????stud->next=NULL; ????stud->next=head; ????head=stud; ????while(scanf("%s",stud->num)&&checknum(stud->num)==0) ????{ ????????printf("輸入錯誤的學(xué)號,重新輸入: "); ????} ????while(scanf("%s",stud->name)&&IncludeChinese(stud->name)==0) ????{ ????????printf("輸入錯誤的名字,重新輸入: "); ????} ????while(scanf("%s",stud->sex)&&IncludeChinese(stud->sex)==0) ????{ ????????printf("輸入錯誤的性別,重新輸入: "); ????} ????while(scanf("%s",stud->room)&&checknum(stud->room)==0) ????{ ????????printf("輸入錯誤的宿舍號碼,重新輸入: "); ????} ????while(scanf("%s",stud->tel)&&checknum(stud->tel)==0) ????{ ????????printf("輸入錯誤的電話號碼,重新輸入: "); ????} ????while(scanf("%s",stud->CHN)&&checkscore(stud->CHN)==0) ????{ ????????printf("輸入錯誤的語文分數(shù),重新輸入: "); ????} ????while(scanf("%s",stud->MATH)&&checkscore(stud->MATH)==0) ????{ ????????printf("輸入錯誤的數(shù)學(xué)分數(shù),重新輸入: "); ????} ????while(scanf("%s",stud->ENG)&&checkscore(stud->ENG)==0) ????{ ????????printf("輸入錯誤的英語分數(shù),重新輸入: "); ????} ????while(scanf("%s",stud->PE)&&checkscore(stud->PE)==0) ????{ ????????printf("輸入錯誤的體育分數(shù),重新輸入: "); ????} ????while(scanf("%s",stud->PRO)&&checkscore(stud->PRO)==0) ????{ ????????printf("輸入錯誤的專業(yè)分數(shù),重新輸入: "); ????} ????Aver=(transformint(stud->CHN)+transformint(stud->MATH)+transformint(stud->ENG)+transformint(stud->PE)+transformint(stud->PRO))/5;//計算平均分 ????itoa(Aver,stud->average_score,10); ????n=n+1;?//節(jié)點+1 ????system("cls"); ????fflush(stdin); ????return(head); } void?update(struct?student?*head)//修改分數(shù) { ????system("cls"); ????fflush(stdin); ????int?Aver; ????struct?student?*p1,*p2; ????char?num[20]={'1'};//用戶即將輸入的學(xué)號 ????char?choose[20]; ????printf("*****************************************************分數(shù)修改*********************************************************** "); ????if(head?==?NULL)//沒有錄信息?空表直接返回 ????{ ????????system("cls"); ????????fflush(stdin); ????????return; ????} ????printf(" ***************************************輸入學(xué)號進行修改學(xué)生分數(shù)(輸入0結(jié)束)********************************************** "); ????do{ ????????printf(" 請輸入學(xué)號:"); ????????while(scanf("%s",num)&&checknum(num)==0) ????????{ ????????????printf("輸入錯誤的學(xué)號,重新輸入: "); ????????} ????????if(transformint(num)==0) ????????{ ????????????break; ????????} ????????p1=p2=head; ????????while(transformint(p1->num)!=transformint(num)&&p1->next!=NULL)//沒找到,往后走 ????????{ ????????????p2=p1; ????????????p1=p1->next; ????????} ????????if(transformint(p1->num)==transformint(num))//找到了,開始選修改的科目 ????????{ ????????????printf("修改語文請輸入1,數(shù)學(xué)輸入2,英語3,體育4,專業(yè)5 "); ????????????printf("請輸入修改科目對應(yīng)的數(shù)字:"); ????????????while(scanf("%s",choose)&&checknum(choose)==0||transformint(choose)<1||transformint(choose)>5) ????????????{ ????????????????printf("輸入無效的編號,重新輸入: "); ????????????} ????????????printf("請輸入修改后的分數(shù):"); ????????????switch(transformint(choose)) ????????????{ ????????????????case?1: ????????????????????while(scanf("%s",p1->CHN)&&checknum(p1->CHN)==0) ????????????????????{ ????????????????????????printf("輸入錯誤的語文分數(shù),重新輸入: "); ????????????????????} ????????????????????break; ????????????????case?2: ????????????????????while(scanf("%s",p1->MATH)&&checknum(p1->MATH)==0) ????????????????????{ ????????????????????????printf("輸入錯誤的數(shù)學(xué)分數(shù),重新輸入: "); ????????????????????} ????????????????????break; ????????????????case?3: ????????????????????while(scanf("%s",p1->ENG)&&checknum(p1->ENG)==0) ????????????????????{ ????????????????????????printf("輸入錯誤的英語分數(shù),重新輸入: "); ????????????????????} ????????????????????break; ????????????????case?4: ????????????????????while(scanf("%s",p1->PE)&&checknum(p1->PE)==0) ????????????????????{ ????????????????????????printf("輸入錯誤的體育分數(shù),重新輸入: "); ????????????????????} ????????????????????break; ????????????????case?5: ????????????????????while(scanf("%s",p1->PRO)&&checknum(p1->PRO)==0) ????????????????????{ ????????????????????????printf("輸入錯誤的專業(yè)分數(shù),重新輸入: "); ????????????????????} ????????????????????break; ????????????} ????????????Aver=(transformint(p1->CHN)+transformint(p1->MATH)+transformint(p1->ENG)+transformint(p1->PE)+transformint(p1->PRO))/5; ????????????itoa(Aver,p1->average_score,10);//平均分轉(zhuǎn)換字符串形式 ????????}else ????????{ ????????????printf("沒有找到學(xué)號為%s的學(xué)生 ",num); ????????} ????}while(transformint(num)!=0); ????system("cls"); ????fflush(stdin); } void?Oscore(struct?student*head)//排序輸出 { ????system("cls"); ????fflush(stdin); ????printf("*****************************************************查看排名*********************************************************** "); ????int?ranking=0; ????struct?student?*p=NULL,*p1=NULL; ????for(p=head;p!=NULL;p=p->next) ????{ ????????if(checkscore(p->average_score)==0) ????????{ ????????????printf("有同學(xué)只錄取了信息,沒有錄成績。所以無法公布排名 "); ????????????system("pause"); ????????????system("cls"); ????????????fflush(stdin); ????????????return; ????????} ????} ????for(p=head;p!=NULL;p=p->next) ????{ ????????for(p1=p->next;p1!=NULL;p1=p1->next) ????????{ ????????????if(transformint(p->average_score) average_score)) ????????????{ ????????????????swap(p,p1); ????????????} ????????} ????} ????printf("學(xué)號 姓名 平均分 名次 語文 數(shù)學(xué) 英語 體育 專業(yè) "); ????for(p=head;p!=NULL;p=p->next) ????{ ????????ranking+=1; ????????printf("%s %s %s %d %s %s %s %s %s ",p->num,p->name,p->average_score,ranking,p->CHN,p->MATH,p->ENG,p->PE,p->PRO); ????} ????printf(" "); ????system("pause"); ????system("cls"); ????fflush(stdin); } void?swap(struct?student*p1,struct?student*p2)//交換數(shù)據(jù)(輔助函數(shù)) { ????char?tempCHN[20]; ????char?tempMATH[20]; ????char?tempENG[20]; ????char?tempPE[20]; ????char?tempPRO[20]; ????char?tempaverage[20]; ????char?tempname[20]; ????char?tempnum[20]; ????strcpy(tempnum,p1->num);/// ????strcpy(p1->num,p2->num); ????strcpy(p2->num,tempnum); ????strcpy(tempname,p1->name);// ????strcpy(p1->name,p2->name); ????strcpy(p2->name,tempname); ????strcpy(tempCHN,p1->CHN);/// ????strcpy(p1->CHN,p2->CHN); ????strcpy(p2->CHN,tempCHN); ????strcpy(tempMATH,p1->MATH);/// ????strcpy(p1->MATH,p2->MATH); ????strcpy(p2->MATH,tempMATH); ????strcpy(tempENG,p1->ENG);/// ????strcpy(p1->ENG,p2->ENG); ????strcpy(p2->ENG,tempENG); ????strcpy(tempPE,p1->PE);/// ????strcpy(p1->PE,p2->PE); ????strcpy(p2->PE,tempPE); ????strcpy(tempPRO,p1->PRO);/// ????strcpy(p1->PRO,p2->PRO); ????strcpy(p2->PRO,tempPRO); ????strcpy(tempaverage,p1->average_score);/// ????strcpy(p1->average_score,p2->average_score); ????strcpy(p2->average_score,tempaverage); } void?fenduan(struct?student*head)//分段輸出 { ????system("cls"); ????fflush(stdin); ????printf("*****************************************************成績分段*********************************************************** "); ????struct?student?*p; ????for(p=head;p!=NULL;p=p->next) ????{ ????????if(checkscore(p->average_score)==0) ????????{ ????????????printf("有同學(xué)只錄取了信息,沒有錄成績。所以無法公布分段 "); ????????????system("pause"); ????????????system("cls"); ????????????fflush(stdin); ????????????return; ????????} ????} ????printf("********************************************************A*************************************************************** "); ????printf("學(xué)號 姓名 平均分 語文 數(shù)學(xué) 英語 體育 專業(yè) "); ????for(p=head;p!=NULL;p=p->next) ????{ ????????if(transformint(p->average_score)>=80) ????????{ ????????????printf("%s %s %s %s %s %s %s %s ",p->num,p->name,p->average_score,p->CHN,p->MATH,p->ENG,p->PE,p->PRO); ????????} ????} ????printf("********************************************************B*************************************************************** "); ????printf("學(xué)號 姓名 平均分 語文 數(shù)學(xué) 英語 體育 專業(yè) "); ????for(p=head;p!=NULL;p=p->next) ????{ ????????if(transformint(p->average_score)<80&&transformint(p->average_score)>=60) ????????{ ????????????printf("%s %s %s %s %s %s %s %s ",p->num,p->name,p->average_score,p->CHN,p->MATH,p->ENG,p->PE,p->PRO); ????????} ????} ????printf("********************************************************C*************************************************************** "); ????printf("學(xué)號 姓名 平均分 語文 數(shù)學(xué) 英語 體育 專業(yè) "); ????for(p=head;p!=NULL;p=p->next) ????{ ????????if(transformint(p->average_score)<60) ????????{ ????????????printf("%s %s %s %s %s %s %s %s ",p->num,p->name,p->average_score,p->CHN,p->MATH,p->ENG,p->PE,p->PRO); ????????} ????} ????printf(" "); ????system("pause"); ????system("cls"); ????fflush(stdin); } void?save(struct?student?*head)//文件保存 { ????system("cls"); ????fflush(stdin); ????FILE?*fp; ????struct?student?*p; ????fp=fopen("stu.db","wb"); ????for(p=head;p!=NULL;p=p->next) ????{ ????????fwrite(p,LEN,1,fp); ????} ????fclose(fp); ????printf("保存完畢 "); ????system("pause"); ????system("cls"); ????fflush(stdin); } void?export1()//文件輸出 { ????system("cls"); ????fflush(stdin); ????FILE?*fp; ????struct?student?*t; ????t=(struct?student?*)malloc(LEN); ????if((fp=fopen("stu.db","r"))==NULL){ ????????printf("未找到文件 "); ????} ????else{ ????????printf("學(xué)號 姓名 平均分 語文 數(shù)學(xué) 英語 體育 專業(yè) "); ????????int?w; ????????fseek(fp,0,2); ????????w=ftell(fp); ????????fseek(fp,0,0); ????????while(w!=ftell(fp)){ ????????????fread(t,LEN,1,fp); ????????????printf("%s %s %s %s %s %s %s %s ",t->num,t->name,t->average_score,t->CHN,t->MATH,t->ENG,t->PE,t->PRO); ????????} ????????fclose(fp); ????} ????system("pause"); ????system("cls"); ????fflush(stdin); } struct?student?*import()//文件導(dǎo)入 { ????system("cls"); ????fflush(stdin); ????FILE?*fp; ????if((fp=fopen("stu.db","r"))==NULL){ ????????printf("未找到文件 "); ????} ????else{ ????????struct?student?*p1,*p2,*head; ????????p1=p2=(struct?student?*)malloc(LEN); ????????fread(p1,LEN,1,fp); ????????while(!feof(fp))?{//end?of?file ????????????n+=1; ????????????if(n==1){ ????????????????head=p1; ????????????} ????????????else{ ????????????????p2->next=p1; ????????????} ????????????p2=p1; ????????????p1=(struct?student?*)malloc(LEN); ????????????fread(p1,LEN,1,fp); ????????} ????????p2->next=NULL; ????????fclose(fp); ????????printf("文件導(dǎo)入成功 "); ????????system("pause"); ????????system("cls"); ????????fflush(stdin); ????????return?head; ????} ????system("cls"); ????fflush(stdin); ????return?NULL; } int?checknum(char?ch[])//檢查純數(shù)字的數(shù)據(jù)里是否混入了非數(shù)字的非法輸入; { ????int?i,flag=1; ????for(i=0;i '9') ????????{ ????????????flag=0; ????????????break; ????????} ????} ????return?flag; } int?checkscore(char?ch[])//檢查0-99分數(shù) { ????int?i,flag=1; ????if(strlen(ch)>=3) ????{ ????????return?0; ????} ????for(i=0;i '9') ????????{ ????????????flag=0; ????????????break; ????????} ????} ????return?flag; } int?IncludeChinese(char?*str)//是否包含中文 { ????char?c; ????while(1) ????{ ????????c=*str++; ????????if?(c==0)?break;??//如果到字符串尾則說明該字符串沒有中文字符 ????????if?(c&0x80)????????//如果字符高位為1且下一字符高位也是1則有中文字符 ????????????if?(*str?&?0x80)?return?1; ????} ????return?0; } int?transformint(char?ch[])//純數(shù)字整數(shù)(字符串轉(zhuǎn)向int類型) { ????int?i=0,sum=0; ????for(i=0;i 審核編輯:湯梓紅
評論
查看更多