




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上#include <iostream.h> #include <iomanip.h> #include <fstream> #include <vector> #include <malloc.h> #include <stdlib.h> #include <string> #include <process.h> #include <stdio.h> #define LEN sizeof(struct student) using namespace std;
2、 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 <student> stu; class Information public: Information() ; /構(gòu)造函數(shù). Information() ;
3、 /析構(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 in
4、order(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<<" -<<歡迎您使用學(xué)生信息管理系統(tǒng)>>-n&
5、quot; cout<<" *nn" Information:Information() /構(gòu)造函數(shù) cout<<" *n" cout<<" -<<謝謝您使用學(xué)生信息管理系統(tǒng)>>-n" cout<<" *n" student *Information:creat(void) /定義一個(gè)指向struct student的結(jié)構(gòu)體指針函數(shù)*creat()用來增加學(xué)生信息. char ch20;n=0; /用來存放姓名的 p1=p2=(student
6、*)malloc(LEN);/調(diào)用malloc()函數(shù)用來開辟一個(gè)新的存儲(chǔ)單元 cout<<" -<<請(qǐng)建立學(xué)生考試信息表,在姓名處輸入 ! 結(jié)束輸入。>>-"<<endl; cout<<"姓名:" cin>>ch; head=NULL; /給指針head賦初值 while (strcmp(ch,"!")!=0) /調(diào)用字符比較函數(shù)strcmp()用來判斷是否繼續(xù)輸入 char str10; int flag=0; p1=(student *)malloc(LEN
7、);/調(diào)用malloc()函數(shù)用來開辟一個(gè)新的存儲(chǔ)單元 strcpy(p1->name,ch); /將循環(huán)結(jié)構(gòu)前面輸入的姓名復(fù)制到結(jié)構(gòu)體名為p1的數(shù)組name中 cout<<" 性別:" cin>>p1->sex; cout<<"院系:" ; cin>>str; cout<<" 學(xué)號(hào)(9位):" do cin>>str; if(atol(str)> | atol(str)<1) cout<<"對(duì)不起,請(qǐng)正確輸入!n&q
8、uot; else p1->id=atol(str); flag=1; while(flag=0); flag=0; cout<<" 語文成績:" do cin>>str; if(atoi(str)>100 | atoi(str)<1) cout<<"對(duì)不起,請(qǐng)輸入1-100之間的數(shù)字!n" else p1->score0=atoi(str); flag=1; while(flag=0); flag=0; cout<<" 外語成績:" do cin>>
9、str; if(atoi(str)>100 | atoi(str)<1) cout<<"對(duì)不起,請(qǐng)輸入1-100之間的數(shù)字!n" else p1->score1=atoi(str); flag=1; while(flag=0); flag=0; cout<<" 數(shù)學(xué)成績:" do cin>>str; if(atoi(str)>100 | atoi(str)<1) cout<<"對(duì)不起,請(qǐng)輸入1-100之間的數(shù)字!n" else p1->score2=a
10、toi(str); flag=1; while(flag=0); flag=0; cout<<" C+成績:" do cin>>str; if(atoi(str)>100 | atoi(str)<1) cout<<"對(duì)不起,請(qǐng)輸入1-100之間的數(shù)字!n" else p1->score3=atoi(str); flag=1; while(flag=0); flag=0; p1->total=p1->score0+p1->score1+p1->score2+p1->scor
11、e3;/計(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 cout<<" 姓名:" cin>>ch;/將輸入的姓名存放到字符數(shù)組ch中 p2->next=NULL;/將p2所指結(jié)構(gòu)體的next指針重新賦空值 return (head);/將輸入的第一組學(xué)生考試信息返回 void Information:output(student *head) /定
12、義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 cout<<s
13、etw(8)<<p1->id <<setw(9)<<p1->name <<setw(8)<<p1->sex <<setw(13)<<p1->score0 <<setw(16)<<p1->score1 <<setw(10)<<p1->score2 <<setw(9)<<p1->score3 <<setw(6)<<p1->total/4.0 <<setw(11)
14、<<p1->total<<endl; cout<<"-n" p1=p1->next;/將下一組學(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ù)的遞
15、歸調(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; cout<<"t-<<請(qǐng)輸入新增學(xué)生成績信息>>-n"<<endl; p1=(student *)malloc(LEN); /使p1指向插入的新結(jié)點(diǎn) cout<<" 姓名:" cin>>p1->name;
16、 /將輸入的姓名存放到結(jié)構(gòu)體名為p1的數(shù)組name中 cout<<" 性別:" cin>>p1->sex; cout<<" 學(xué)號(hào)(9位):" do cin>>str; if(atol(str)> | atol(str)<1) cout<<"對(duì)不起,請(qǐng)請(qǐng)正確輸入!n" else p1->id=atol(str); flag=1; while(flag=0); flag=0; cout<<" 語文成績:" do cin>
17、;>str; if(atoi(str)>100 | atoi(str)<1) cout<<"對(duì)不起,請(qǐng)輸入1-100之間的數(shù)字!n" else p1->score0=atoi(str); flag=1; while(flag=0); flag=0; cout<<" 外語成績:" do cin>>str; if(atoi(str)>100 | atoi(str)<1) cout<<"對(duì)不起,請(qǐng)輸入1-100之間的數(shù)字!n" else p1->sco
18、re1=atoi(str); flag=1; while(flag=0); flag=0; cout<<" 數(shù)學(xué)成績:" do cin>>str; if(atoi(str)>100 | atoi(str)<1) cout<<"對(duì)不起,請(qǐng)輸入1-100之間的數(shù)字!n" else p1->score2=atoi(str); flag=1; while(flag=0); flag=0; cout<<" C+成績:" do cin>>str; if(atoi(str
19、)>100 | atoi(str)<1) cout<<"對(duì)不起,請(qǐng)輸入1-100之間的數(shù)字!n" else p1->score3=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并
20、將p1所指結(jié)構(gòu)體成員指針next賦空值 else while(p1->id>p2->id)&&(p2->next!=NULL) p3=p2;/p3指向原p2指向的結(jié)點(diǎn) p2=p2->next; /p2后移一個(gè)結(jié)點(diǎn) if(p1->id<=p2->id) 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; /插
21、入到尾結(jié)點(diǎn)之后 n+;/將學(xué)生人數(shù)加1 cout<<"t你輸入的學(xué)生信息已經(jīng)成功插入"<<endl; return (head); /刪除學(xué)生信息函數(shù) student *Information:cancel(student *head,long int num)/定義一個(gè)指向struct student的結(jié)構(gòu)體指針函數(shù)*delete()用來刪除考生信息. if(head=NULL)/若調(diào)用次函數(shù)以前的頭指針head為空 return(head); else p1=head;/否則將頭指針賦給p1 while(num!=p1->id&&a
22、mp;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)為&qu
23、ot;<<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為空 cout<<" 這是一個(gè)空表,請(qǐng)先輸入考生成績.n" return(head); else p1=head;/否則將頭指針賦給p1 whi
24、le(num!=p1->id&&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" cout<<setw(8)<<p1->id <&l
25、t;setw(9)<<p1->name <<setw(8)<<p1->sex <<setw(13)<<p1->score0 <<setw(16)<<p1->score1 <<setw(10)<<p1->score2 <<setw(9)<<p1->score3 <<setw(6)<<p1->total/4.0 <<setw(11)<<p1->total<<en
26、dl; 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&
27、lt;<"-n" cout<<"學(xué)生成績統(tǒng)計(jì)表n" cout<<"-n" cout<<"學(xué)號(hào) 姓 名 性別 院系 語文 英語 數(shù)學(xué) C+ 平均分 總分 名次n" cout<<"-n" p1=head; for(k=0;k<m;k+) pk=p1; p1=p1->next; for(k=0;k<m-1;k+) /選擇排序法 for(j=k+1;j<m;j+) if(pk->total<pj->total
28、) p2=pk; pk=pj; pj=p2; for(i=0;i<m;i+) cout<<setw(8)<<p1->id <<setw(9)<<p1->name <<setw(8)<<p1->sex <<setw(13)<<p1->score0 <<setw(16)<<p1->score1 <<setw(10)<<p1->score2 <<setw(9)<<p1->score3 &
29、lt;<setw(6)<<p1->total/4.0 <<setw(11)<<p1->total<<endl; 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);
30、p1=head; for(k=0;k<m;k+) arg1+=p1->score0; 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 <<" 英語平
31、均分:"<<setw(7)<<arg2 <<" 數(shù)學(xué)平均分:"<<setw(7)<<arg3 <<" C+平均分:"<<setw(7)<<arg4<<endl; cout<<"-n" void Information:save(student *head) /保存函數(shù). ofstream out("data.txt",ios:out); out<<count(head)<
32、;<endl; while(head!=NULL) out<<head->name<<"t" <<head->id<<"t"<<"t" <<head->sex<<"t" <<head->score0<<"t" <<head->score1<<"t" <<head->score2<<
33、"t" <<head->score3<<"t" <<head->total<<endl; head=head->next; student *Information:Read() /讀取函數(shù)的實(shí)現(xiàn) int i=0; p1=p2=( student *)malloc(LEN); head=NULL; ifstream in("data.txt",ios:out); in>>i; if(i=0)cout<<" data.txt 文件中的數(shù)據(jù)
34、為空,請(qǐng)先輸入數(shù)據(jù)。"<<endl; return 0; else cout<<" "<<endl; for(;i>0;i-) p1=(student *)malloc(LEN); cin>>>>st.id>>st.sex >>st.score0>>st.score1>>st.score2>>st.score3 >>st.total; strcpy(p1->name,); p1->id=s
35、t.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<<" "
36、<<p1->name<<"t" /顯示讀入數(shù)據(jù) <<p1->id<<"t"<<"t" <<p1->sex<<"t" <<p1->score0<<"t" <<p1->score1<<"t" <<p1->score2<<"t" <<p1->score3&
37、lt;<"t" <<p1->total<<endl; cout<<" "<<endl; / cout<<" 數(shù)據(jù)已經(jīng)成功讀取完畢。"<<endl; p2->next=NULL; return (head); int main() /主函數(shù). system("color 4f");/改變登陸界面顏色 Information person; student *head=NULL; char str5; int flag=0; in
38、t choice; long int i; char admin20; char pass30; cout<<"請(qǐng)輸入賬號(hào)n" cin>>admin; cout<<"請(qǐng)輸入密碼n" cin>>pass; if(strcmp(admin,"1111")=0&&strcmp(pass,"222")=0) do cout<<" *"<<endl; cout<<" 學(xué)生信息管理系統(tǒng)主菜單界面 *"<<endl ; cout<<" "<<endl; cout<<""<<endl; cout<<" .輸入學(xué)生信息 "<<endl; cout<<" .顯示學(xué)生信息 "<<endl; cout<<" .排序統(tǒng)計(jì)成績 "<<endl; cout<<" .查找學(xué)生信息 "<<endl; cout<<
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- YY/T 1946-2024腫瘤組織基因突變檢測(cè)試劑盒(高通量測(cè)序法)
- 農(nóng)副產(chǎn)品購銷示范合同
- 簽訂的門面租賃合同條款解析
- 建筑項(xiàng)目施工合同管理人員聘用合同
- 炒股合作經(jīng)典合同案例
- 車輛采購合同細(xì)則
- 國際物流服務(wù)合同專業(yè)版詳解
- 農(nóng)村土地流轉(zhuǎn)授權(quán)合同書
- 城市房屋拆遷補(bǔ)償安置標(biāo)準(zhǔn)合同樣本
- 鋼材買賣合同(示范文本GF-0155)
- 骶髂關(guān)節(jié)損傷郭倩課件
- 內(nèi)科學(xué)疾病概要-支氣管擴(kuò)張課件
- 2025陜西渭南光明電力集團(tuán)限公司招聘39人易考易錯(cuò)模擬試題(共500題)試卷后附參考答案
- 預(yù)防感冒和流感的方法
- 2024年黑龍江職業(yè)學(xué)院高職單招語文歷年參考題庫含答案解析
- 2024年南京旅游職業(yè)學(xué)院高職單招語文歷年參考題庫含答案解析
- 股指期貨基礎(chǔ)知識(shí)介紹培訓(xùn)課件
- 2024年北京東城社區(qū)工作者招聘筆試真題
- xx學(xué)校培訓(xùn)部工作職責(zé)
- T-GXAR 005-2024 制冷機(jī)房運(yùn)行維護(hù)規(guī)程
- 開工第一課安全培訓(xùn)總結(jié)精彩
評(píng)論
0/150
提交評(píng)論