




已閱讀5頁,還剩9頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
#include #include #include #include #include #include #include #include #include #define LEN sizeof(struct student) using namespace std; int n=0; /定義一個(gè)全局變量統(tǒng)計(jì)學(xué)生人數(shù) struct student/定義一個(gè)學(xué)生信息的結(jié)構(gòu)體 char name20; /用來存放姓名的 char sex20; /用來存放性別的 char yuanxi20;/用來存放院系的 long int id; /用來存放學(xué)號(hào)的 int score4; /用來存放分?jǐn)?shù)的 int total; /用來存放總分?jǐn)?shù)的 struct student *next; ; vector stu; class Information public: Information() ; /構(gòu)造函數(shù). Information() ; /析構(gòu)函數(shù). student *creat();/建立鏈表函數(shù)。 void output(student *head); int count(student *head);/定義函數(shù)count()統(tǒng)計(jì)考生總數(shù) student *insert(student*head);/指針函數(shù)*insert()用來添加考生信息. student *cancel(student *head,long int num);/指針函數(shù)*cancel()用來刪除考生信息. student *find(student *head,long int num); /指針函數(shù)*find()用來查找考生信息. void inorder(student *head);/定義inorder()函數(shù)將考生的總分從大到小排列并輸出 void average( student *head);/求學(xué)生成績的平均分的函數(shù) void save(student *head);/保存函數(shù) student *Read();/讀取函數(shù) private: student *p1,*p2,*p3,*head,st; ; Information:Information() /構(gòu)造函數(shù) cout *n; cout -n; cout *nn; Information:Information() /構(gòu)造函數(shù) cout *n; cout -n; cout *n; student *Information:creat(void) /定義一個(gè)指向struct student的結(jié)構(gòu)體指針函數(shù)*creat()用來增加學(xué)生信息. char ch20;n=0; /用來存放姓名的 p1=p2=(student *)malloc(LEN);/調(diào)用malloc()函數(shù)用來開辟一個(gè)新的存儲(chǔ)單元 cout -endl; coutch; head=NULL; /給指針head賦初值 while (strcmp(ch,!)!=0) /調(diào)用字符比較函數(shù)strcmp()用來判斷是否繼續(xù)輸入 char str10; int flag=0; p1=(student *)malloc(LEN);/調(diào)用malloc()函數(shù)用來開辟一個(gè)新的存儲(chǔ)單元 strcpy(p1-name,ch); /將循環(huán)結(jié)構(gòu)前面輸入的姓名復(fù)制到結(jié)構(gòu)體名為p1的數(shù)組name中 coutp1-sex; coutstr; coutstr; if(atol(str)999999999 | atol(str)1) coutid=atol(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore0=atoi(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore1=atoi(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore2=atoi(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore3=atoi(str); flag=1; while(flag=0); flag=0; p1-total=p1-score0+p1-score1+p1-score2+p1-score3;/計(jì)算總分 if(n=0)head=p1;/如果是輸入第一組學(xué)生考試信息就將指針p1賦給指針head else p2-next=p1;/否則將p1賦給p2所指結(jié)構(gòu)體的next指針 p2=p1;/將指針p1賦給指針p2 n+; /將n的值加1 coutch;/將輸入的姓名存放到字符數(shù)組ch中 p2-next=NULL;/將p2所指結(jié)構(gòu)體的next指針重新賦空值 return (head);/將輸入的第一組學(xué)生考試信息返回 void Information:output(student *head) /定義output()函數(shù)將學(xué)生的信息從頭指針?biāo)竷?nèi)容開始輸出 if(head=NULL) cout 這是一個(gè)空表,請(qǐng)先輸入考生成績.n; else cout-n; cout *學(xué)生成績信息表*n; cout-n; cout學(xué)號(hào) 姓 名 性別 院系 語文 英語 數(shù)學(xué) C+ 平均成績 總分n; cout-n; p1=head;/將頭指針賦給p do coutsetw(8)id setw(9)name setw(8)sex setw(13)score0 setw(16)score1 setw(10)score2 setw(9)score3 setw(6)total/4.0 setw(11)totalendl; coutnext;/將下一組學(xué)生信息的next指針賦給p while(p1!=NULL);/若指針p非空則繼續(xù),目的是把所有的學(xué)生信息都傳給指針p然后輸出. /統(tǒng)計(jì)學(xué)生人數(shù)的函數(shù) int Information:count(struct student *head)/定義函數(shù)count()統(tǒng)計(jì)考生總數(shù) if(head=NULL) /若指針head為空返回值為0 return(0); else return(1+count(head-next);/函數(shù)的遞歸調(diào)用 /插入學(xué)生的成績信息的函數(shù) student *Information:insert( student *head) /插入新結(jié)點(diǎn)定義一個(gè)指向struct student的結(jié)構(gòu)體指針函數(shù)*insert()用來添加考生信息. char str10; int flag=0; coutt-nendl; p1=(student *)malloc(LEN); /使p1指向插入的新結(jié)點(diǎn) coutp1-name; /將輸入的姓名存放到結(jié)構(gòu)體名為p1的數(shù)組name中 coutp1-sex; coutstr; if(atol(str)99999999 | atol(str)1) coutid=atol(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore0=atoi(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore1=atoi(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore2=atoi(str); flag=1; while(flag=0); flag=0; coutstr; if(atoi(str)100 | atoi(str)1) coutscore3=atoi(str); flag=1; while(flag=0); flag=0; p1-total=p1-score0+p1-score1+p1-score2+p1-score3;/計(jì)算總分 p2=head;/將頭指針賦給p2 if(head=NULL) /若沒調(diào)用次函數(shù)以前的頭指針head為空 head=p1;p1-next=NULL;/則將p1賦給頭指針head并將p1所指結(jié)構(gòu)體成員指針next賦空值 else while(p1-idp2-id)&(p2-next!=NULL) p3=p2;/p3指向原p2指向的結(jié)點(diǎn) p2=p2-next; /p2后移一個(gè)結(jié)點(diǎn) if(p1-idid) if(head=p2) p1-next=head; head=p1; /插入到第一個(gè)結(jié)點(diǎn)之前 else p3-next=p1; p1-next=p2; /插入到p3所指結(jié)點(diǎn)之后 else p2-next=p1; p1-next=NULL; /插入到尾結(jié)點(diǎn)之后 n+;/將學(xué)生人數(shù)加1 coutt你輸入的學(xué)生信息已經(jīng)成功插入id&p1-next!=NULL)/尋找要?jiǎng)h除的結(jié)點(diǎn)當(dāng)p1所指的學(xué)號(hào)不是輸入的學(xué)號(hào)并且p1所指的next指針不為空 p2=p1; p1=p1-next; /p2指向原p1指向的結(jié)點(diǎn)p1后移一個(gè)結(jié)點(diǎn) if(num=p1-id)/如果輸入的學(xué)生準(zhǔn)考證號(hào)是p1所指的學(xué)號(hào)結(jié)點(diǎn)找到后刪除 if(p1=head) head=p1-next;/如果head指針和p1指針相等則將下一個(gè)結(jié)點(diǎn)賦給指針head else p2-next=p1-next;/否則將p1所指結(jié)點(diǎn)賦給p2所指結(jié)點(diǎn)將要?jiǎng)h除的學(xué)生信息跳過去 cout 刪除學(xué)號(hào)為num的學(xué)生n; n-;/將學(xué)生人數(shù)減1 return(head);/將頭指針返回 /查找學(xué)生信息函數(shù) student *Information:find(student *head,long int num) /定義一個(gè)指向struct student的結(jié)構(gòu)體指針函數(shù)*find()用來查找學(xué)生信息. if(head=NULL)/若調(diào)用次函數(shù)以前的頭指針head為空 coutid&p1-next!=NULL) /尋找結(jié)點(diǎn)當(dāng)p1所指的學(xué)號(hào)不是輸入的學(xué)生學(xué)號(hào)并且p1所指的next指針不為空 p1=p1-next; /p1后移一個(gè)結(jié)點(diǎn) if(num=p1-id)/如果要查找的學(xué)號(hào)是p1所指的學(xué)號(hào) cout-n; cout學(xué)號(hào) 姓名 性別 院系 語文 英語 數(shù)學(xué) C+ 平均分 總分 n; cout-n; coutsetw(8)id setw(9)name setw(8)sex setw(13)score0 setw(16)score1 setw(10)score2 setw(9)score3 setw(6)total/4.0 setw(11)totalendl; cout-n; else cout 沒找到學(xué)號(hào)為num的學(xué)生.n; /結(jié)點(diǎn)沒找到 return(head); void Information:inorder(student *head) /定義inorder()函數(shù)將考生的總分從大到小排列并輸出 int i,k,m=0,j; student *p20;/定義一個(gè)指向struct student的結(jié)構(gòu)體指針數(shù)組p if(head!=NULL)/如果頭指針是空則繼續(xù) m=count(head); cout-n; cout學(xué)生成績統(tǒng)計(jì)表n; cout-n; cout學(xué)號(hào) 姓 名 性別 院系 語文 英語 數(shù)學(xué) C+ 平均分 總分 名次n; cout-n; p1=head; for(k=0;knext; for(k=0;km-1;k+) /選擇排序法 for(j=k+1;jtotaltotal) p2=pk; pk=pj; pj=p2; for(i=0;im;i+) coutsetw(8)id setw(9)name setw(8)sex setw(13)score0 setw(16)score1 setw(10)score2 setw(9)score3 setw(6)total/4.0 setw(11)totalendl; cout-n; void Information:average(student *head) /求各科平均成績的函數(shù) int k,m; float arg1=0,arg2=0,arg3=0,arg4=0; if(head=NULL)/如果頭指針是空則繼續(xù) cout 這是一個(gè)空表,請(qǐng)先輸入學(xué)生成績.n; else m=count(head); p1=head; for(k=0;kscore0; arg2+=p1-score1; arg3+=p1-score2; arg4+=p1-score3; p1=p1-next; arg1/=m;arg2/=m;arg3/=m;arg4/=m; cout全班單科成績平均分n; cout-n; cout 語文平均分:setw(7)arg1 英語平均分:setw(7)arg2 數(shù)學(xué)平均分:setw(7)arg3 C+平均分:setw(7)arg4endl; cout-n; void Information:save(student *head) /保存函數(shù). ofstream out(data.txt,ios:out); outcount(head)endl; while(head!=NULL) outnamet idtt sext score0t score1t score2t score3t totalnext; student *Information:Read() /讀取函數(shù)的實(shí)現(xiàn) int i=0; p1=p2=( student *)malloc(LEN); head=NULL; ifstream in(data.txt,ios:out); ini; if(i=0)cout data.txt 文件中的數(shù)據(jù)為空,請(qǐng)先輸入數(shù)據(jù)。endl; return 0; else cout 0;i-) p1=(student *)malloc(LEN); st.idst.sex st.score0st.score1st.score2st.score3 st.total; strcpy(p1-name,); p1-id=st.id; strcpy(p1-sex,st.sex); p1-score0=st.score0; p1-score1=st.score1; p1-score2=st.score2; p1-score3=st.score3; p1-total=st.total; if(n=0)head=p1;/如果是輸入第一組學(xué)生考試信息就將指針p1賦給指針head else p2-next=p1;/否則將p1賦給p2所指結(jié)構(gòu)體的next指針 p2=p1;/將指針p1賦給指針p2 n+; /將n的值加1 cout namet /顯示讀入數(shù)據(jù) idtt sext score0t score1t score2t score3t totalendl; cout endl; / cout 數(shù)據(jù)已經(jīng)成功讀取完畢。next=NULL; return (head); int main() /主函數(shù). system(color 4f);/改變登陸界面顏色 Information person; student *head=NULL; char str5; int flag=0; int choice; long int i; char admin20; char pass30; coutadmin; coutpass; if(strcmp(admin,1111)=0&strcmp(pass,222)=0) do cout *endl; cout 學(xué)生信息管理系統(tǒng)主菜單界面 *endl ; cout endl; coutendl; cout .輸入學(xué)生信息 endl; cout .顯示學(xué)生信息 endl; cout .排序統(tǒng)計(jì)成績 endl; cout .查找學(xué)生信息 endl; cout .增加學(xué)生信息 endl; cout .刪除學(xué)生信息 endl; cout .保存退出系統(tǒng) endl; coutendl; coutstr; if(atoi(str)7 | atoi(str
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 法律文化在法治建設(shè)中的作用與價(jià)值試題及答案
- 班主任與學(xué)生溝通技巧的提升計(jì)劃
- 軟考網(wǎng)絡(luò)管理員備考計(jì)劃試題及答案
- 人才招聘與培養(yǎng)計(jì)劃
- 結(jié)合客戶反饋優(yōu)化生產(chǎn)流程計(jì)劃
- 自然語言處理技術(shù)進(jìn)展試題及答案
- 2024年沈陽工程學(xué)院輔導(dǎo)員考試真題
- 2025年法學(xué)概論百科全書式試題及答案
- 2024年吉林省醫(yī)療保障局下屬事業(yè)單位真題
- 2024年塔城地區(qū)中醫(yī)醫(yī)院招聘筆試真題
- 礦井防爆門(防爆井蓋)安全檢測技術(shù)規(guī)范
- 山水田園詩鑒賞公開課一等獎(jiǎng)市賽課一等獎(jiǎng)?wù)n件
- 酒店管理會(huì)所希爾頓酒店設(shè)計(jì)標(biāo)準(zhǔn)第節(jié)電梯電扶梯
- 福建新費(fèi)用定額交底材料
- 器質(zhì)性精神障礙患者的護(hù)理
- 趣味英語課件完整版
- 大學(xué)武術(shù)智慧樹知到答案章節(jié)測試2023年浙江大學(xué)
- 前列腺增生癥患者圍手術(shù)期的護(hù)理
- 五防系統(tǒng)調(diào)試報(bào)告
- 日語綜合教程第六冊(cè) 單詞表
- 市委政研室主任關(guān)于如何寫稿子的講話
評(píng)論
0/150
提交評(píng)論