




已閱讀5頁,還剩4頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
#include #include #include #include #include #include #include #include #include using namespace std;struct student char name12; / 姓名 char id10; / 學(xué)號(hào) float Computer; / 計(jì)算機(jī)分?jǐn)?shù) float Math; / 數(shù)學(xué)分?jǐn)?shù) float Chinese; / 語文分?jǐn)?shù) float English; /英語分?jǐn)?shù) float number; / 總分 float average; /平均分 student *next;class stud student *p1,*p2,*head;public: stud() /-析構(gòu)函數(shù)- while(head) p1=head-next; delete head; head=p1; /-成員函數(shù)-student* input(student *head); / 輸入學(xué)生成績(jī) void output(student *head); / 輸出學(xué)生成績(jī) student* del(student *head, char*p); / 刪除記錄 student* find(student *head,char *p,int &n);/ 查找學(xué)生記錄(可查找多個(gè)同名數(shù)據(jù)) student* search(student *head,char *p,int &n); student* stat(student *head); /排序統(tǒng)計(jì)學(xué)生總分 friend void total(student*head);/統(tǒng)計(jì)學(xué)生總分 friend void pingjun(student*head);/統(tǒng)計(jì)平均分 student* insert(student *head); /按學(xué)生總分插入記錄 student* clear(student *head); / 刪除當(dāng)前表 void Inputs(student *p); /用于添加數(shù)據(jù)的子函數(shù);/-void stud:Inputs(student*p)/ 輸入學(xué)生成績(jī) coutsetw(4)姓名setw(4) 學(xué)號(hào)setw(12)計(jì)算機(jī)setw(12)數(shù)學(xué)setw(12)語文setw(12)英語p-name p-id; cin p-Computer; while(cin.fail() cout您的輸入有誤,請(qǐng)重新輸入p-Computer; cinp-Math; while(cin.fail() cout您的輸入有誤,請(qǐng)重新輸入p-Math; cinp-Chinese; while(cin.fail() cout您的輸入有誤,請(qǐng)重新輸入p-Chinese; cinp-English; while(cin.fail() cout您的輸入有誤,請(qǐng)重新輸入p-English; total(p); /計(jì)算出總分 pingjun(p);/計(jì)算平均分void stud:output (student *head)/輸出學(xué)生成績(jī) p1=head; while(p1!=NULL) coutsetw(4)namesetw(4)idsetw(12)Computersetw(12)Math setw(12)Chinese setw(12)English setw(8)numbersetw(12)averagenext ; student* stud:insert(student *head) p1=new student;/指向要插入的節(jié)點(diǎn) Inputs(p1); /調(diào)用子函數(shù) 增加數(shù)據(jù) p2=head;/使p2指向第一個(gè)節(jié)點(diǎn) student* p3=NULL; while(p2-number number ) & p2-next !=NULL) p3=p2;/使p3指向剛剛p2指向的節(jié)點(diǎn) p2=p2-next;/p2后移一個(gè)節(jié)點(diǎn) if(p2-number p1-number) p1-next=p2; if(p3=NULL) / 若當(dāng)前值是最小的 return p1; p3-next =p1; return head; else p2-next=p1; p1-next=NULL; return head; student* stud:clear(student*head) while(head) p1=head-next ; delete head; head=p1; return head;student *stud:stat(student *head) p2=head; p1=p2-next; while(p2-next) /起泡法 if(p2-number p1-number) / 把頭指針指向當(dāng)前比較小的節(jié)點(diǎn) p2-next=p1-next; p1-next=head; head=p1; / 把用于比較的兩個(gè)指針復(fù)位 /p2=head; p1=p2-next ; else / 指向下一個(gè)節(jié)點(diǎn) p2=p2-next ; p1=p2-next ; /- cout當(dāng)前表以按學(xué)生總分排序成功id ,p)& p1-next !=NULL) p2=p1; p1=p1-next ; if(!strcmp(p1-id ,p) if(p1=head) head=p1-next; else p2-next=p1-next ; cout刪除成功,OKendl; delete p1; else cout 沒找到姓名pnumber = p-Computer + p-Math + p-Chinese+ p-English; void pingjun(student *p) p-average=(p-Computer+p-Math+p-Chinese+p-English)/4; student* stud:find (student *head,char *p,int& n) p2=head; while(strcmp(p2-name ,p) !=0 & p2-next !=NULL) p2=p2-next ; if(0=strcmp(p2-name,p) coutsetw(4)namesetw(4)idsetw(12)Computersetw(12)Math setw(12)Chinese setw(12)Englishsetw(7)number setw(12)averageendl; n+; return p2; else if(n=0) system(cls); cout對(duì)不起,沒有您要查找的學(xué)生數(shù)據(jù)id ,p) !=0 & p2-next !=NULL) p2=p2-next ; if(0=strcmp(p2-id,p) coutsetw(4)namesetw(4)idsetw(12)Computersetw(12)Math setw(12)Chinese setw(12)Englishsetw(7)number setw(12)averageendl; n+; return p2; else if(n=0) system(cls); cout對(duì)不起,沒有您要查找的學(xué)生數(shù)據(jù)next =NULL; return head; while(p2-next !=NULL) p2=p2-next; p2-next=p1; p1-next=NULL; return head;void error() cout錯(cuò)誤,這還是一張空表,請(qǐng)輸入數(shù)據(jù)endl; getch();int main() stud stus; student *head=NULL;/鏈表初始化 student *pd; /臨時(shí)指針, 用于查找函數(shù) char choice; /用于存放用戶的選擇項(xiàng) char name10; /查找,刪除記錄的 key while(1) system(cls); cout*n; cout 學(xué)生成績(jī)管理系統(tǒng) n;cout*Meau*n;cout1.輸入學(xué)生成績(jī)記錄n; cout2.顯示學(xué)生成績(jī)記錄n; cout3.修改學(xué)生成績(jī)記錄n; cout4.按姓名查找學(xué)生成績(jī)記錄n; cout5.按學(xué)號(hào)查找學(xué)生成績(jī)記錄n; cout6.刪除學(xué)生成績(jī)記錄n; cout7.插入學(xué)生成績(jī)記錄n; cout8.全表刪除n; cout9.退出n;cout*n; cout 請(qǐng)輸入您的選擇(1-8):; coutchoice; fflush(stdin); /清空緩沖區(qū) if(choice=9) /安全退出 cout謝謝使用,再見endl; exit(0); /- switch(choice) case 1: head=stus.input (head); break;/- case 2: if(head=NULL) error(); break; coutsetw(4)姓名setw(4) 學(xué)號(hào)setw(12)數(shù)據(jù)結(jié)構(gòu)setw(12)操作系統(tǒng)setw(12)組成原理setw(12)計(jì)算機(jī)網(wǎng)絡(luò)setw(8)總分setw(10)平均分endl; stus.output (head); getch();/從鍵盤獲取一個(gè)字符 break;/- case 3: if(head=NULL) error(); break; char id10; cout請(qǐng)輸入想要修改學(xué)生學(xué)號(hào)id; head=stus.del(head,id); head=stus.input (head); break;/- case 4: if(head =NULL) error(); /調(diào)用函數(shù)輸出錯(cuò)誤信息 break; cout請(qǐng)輸入想要查找的學(xué)生姓名name; pd=head; coutsetw(4)姓名setw(4) 學(xué)號(hào)setw(12)計(jì)算機(jī)setw(12)數(shù)學(xué)setw(12)語文setw(12)英語setw(8)總分setw(10)平均分next ; /指針指向當(dāng)前以找到的下一個(gè)節(jié)點(diǎn),用于查找多個(gè)同名學(xué)生 getch(); break;/- case 5: if(head =NULL) error(); /調(diào)用函數(shù)輸出錯(cuò)誤信息 break; cout請(qǐng)輸入想要查找的學(xué)生學(xué)號(hào)id; pd=head; coutsetw(4)姓名setw(4) 學(xué)號(hào)setw(12)計(jì)算機(jī)setw(12)數(shù)學(xué)setw(12)語文setw(12)英語setw(8)總分setw(10)平均分next ; /指針指向當(dāng)前以找到的下一個(gè)節(jié)點(diǎn),用于查找多個(gè)同名學(xué)生 getch(); break;/- case 6: if(head=NULL) error(); break; cout請(qǐng)輸入想要?jiǎng)h除學(xué)生學(xué)號(hào)id; head=stus.del(head,id); getch(); break;/- case 7: if(head=NULL) err
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 阿托品考試試題及答案
- 口譯考試試題及答案
- 關(guān)于廠房分租合同范例
- 甘肅省武威市第十七中學(xué)2025春小升初語文部編版模擬練習(xí)題(有答案)
- 云南省名校聯(lián)盟2025屆高三月考化學(xué)及答案(八)
- 為單位維修合同范例
- 農(nóng)場(chǎng)品采購合同范例
- 企業(yè)業(yè)務(wù)提成合同范例
- 共享加盟合同范例
- 全屋家具合同范例
- 《excel數(shù)據(jù)分析》課件
- DB1310-T 223-2020 小麥節(jié)水綠色豐產(chǎn)栽培技術(shù)規(guī)程
- 小學(xué)六年級(jí)科學(xué)(人教版)《各種各樣的自然資源》-教學(xué)設(shè)計(jì)、課后練習(xí)、學(xué)習(xí)任務(wù)單
- 215kWh工商業(yè)液冷儲(chǔ)能電池一體柜用戶手冊(cè)
- 燃?xì)獍踩鹿侍幚砑皯?yīng)急
- 汽車發(fā)動(dòng)機(jī)構(gòu)造與維修課件 第六章 燃油供給系
- 可再生能源預(yù)測(cè)技術(shù)研究
- 2024-2030年中國耐火材料行業(yè)供需分析及發(fā)展前景研究報(bào)告
- 部門級(jí)安全培訓(xùn)考試題附答案【考試直接用】
- 物業(yè)五級(jí)三類服務(wù)統(tǒng)一標(biāo)準(zhǔn)
- 見證取樣手冊(cè)(給排水管道工程分部)
評(píng)論
0/150
提交評(píng)論