學生信息管理系統(tǒng)C++語言程序代碼_第1頁
學生信息管理系統(tǒng)C++語言程序代碼_第2頁
學生信息管理系統(tǒng)C++語言程序代碼_第3頁
學生信息管理系統(tǒng)C++語言程序代碼_第4頁
學生信息管理系統(tǒng)C++語言程序代碼_第5頁
已閱讀5頁,還剩9頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、.#include #include #include #include #include #include #include #include #include #define LEN sizeof(struct student) using namespace std; int n=0; /定義一個全局變量統(tǒng)計學生人數(shù) struct student/定義一個學生信息的結構體 char name20; /用來存放姓名的 char sex20; /用來存放性別的 char yuanxi20;/用來存放院系的 long int id; /用來存放學號的 int score4; /用來存放分數(shù)的

2、int total; /用來存放總分數(shù)的 struct student *next; ; vector stu; class Information public: Information() ; /構造函數(shù). Information() ; /析構函數(shù). student *creat();/建立鏈表函數(shù)。 void output(student *head); int count(student *head);/定義函數(shù)count()統(tǒng)計考生總數(shù) student *insert(student*head);/指針函數(shù)*insert()用來添加考生信息. student *cancel(stu

3、dent *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);/求學生成績的平均分的函數(shù) void save(student *head);/保存函數(shù) student *Read();/讀取函數(shù) private: student *p1,*p2,*p3,*he

4、ad,st; ; Information:Information() /構造函數(shù) cout *n; cout -n; cout *nn; Information:Information() /構造函數(shù) cout *n; cout -n; cout *n; student *Information:creat(void) /定義一個指向struct student的結構體指針函數(shù)*creat()用來增加學生信息. char ch20;n=0; /用來存放姓名的 p1=p2=(student *)malloc(LEN);/調(diào)用malloc()函數(shù)用來開辟一個新的存儲單元 cout -endl; c

5、outch; 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ù)用來開辟一個新的存儲單元 strcpy(p1-name,ch); /將循環(huán)結構前面輸入的姓名復制到結構體名為p1的數(shù)組name中 coutp1-sex; coutstr; coutstr; if(atol(str)999999999 | atol(str)1) coutid=atol(str); flag=1

6、; 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;

7、 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;/計算總分 if(n=0)head=p1;/如果是輸入第一組學生考試信息就將指針p1賦給指針head else p2-next=p1;/否則將p1賦給p2所指結構體的next指針 p2=p1;/將指針p1賦給指針p2 n+; /將n的值加1 coutch;/將輸入的姓名存放到字符數(shù)組ch中 p2-next=NULL

8、;/將p2所指結構體的next指針重新賦空值 return (head);/將輸入的第一組學生考試信息返回 void Information:output(student *head) /定義output()函數(shù)將學生的信息從頭指針所指內(nèi)容開始輸出 if(head=NULL) cout 這是一個空表,請先輸入考生成績.n; else cout-n; cout *學生成績信息表*n; cout-n; cout學號 姓 名 性別 院系 語文 英語 數(shù)學 C+ 平均成績 總分n; cout-n; p1=head;/將頭指針賦給p do coutsetw(8)id setw(9)name setw(8

9、)sex setw(13)score0 setw(16)score1 setw(10)score2 setw(9)score3 setw(6)total/4.0 setw(11)totalendl; coutnext;/將下一組學生信息的next指針賦給p while(p1!=NULL);/若指針p非空則繼續(xù),目的是把所有的學生信息都傳給指針p然后輸出. /統(tǒng)計學生人數(shù)的函數(shù) int Information:count(struct student *head)/定義函數(shù)count()統(tǒng)計考生總數(shù) if(head=NULL) /若指針head為空返回值為0 return(0); else re

10、turn(1+count(head-next);/函數(shù)的遞歸調(diào)用 /插入學生的成績信息的函數(shù) student *Information:insert( student *head) /插入新結點定義一個指向struct student的結構體指針函數(shù)*insert()用來添加考生信息. char str10; int flag=0; coutt-nendl; p1=(student *)malloc(LEN); /使p1指向插入的新結點 coutp1-name; /將輸入的姓名存放到結構體名為p1的數(shù)組name中 coutp1-sex; coutstr; if(atol(str)9999999

11、9 | 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=a

12、toi(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;/計算總分 p2=head;/將頭指針賦給p2 if(head=NULL) /若沒調(diào)用次函數(shù)以前的頭指針head為空 head=p1;p1-next=NULL;/則將p1賦給頭指針head并將p1所指結構體成員指針next賦空值 els

13、e while(p1-idp2-id)&(p2-next!=NULL) p3=p2;/p3指向原p2指向的結點 p2=p2-next; /p2后移一個結點 if(p1-idid) if(head=p2) p1-next=head; head=p1; /插入到第一個結點之前 else p3-next=p1; p1-next=p2; /插入到p3所指結點之后 else p2-next=p1; p1-next=NULL; /插入到尾結點之后 n+;/將學生人數(shù)加1 coutt你輸入的學生信息已經(jīng)成功插入id&p1-next!=NULL)/尋找要刪除的結點當p1所指的學號不是輸入的學號并且p1所指的n

14、ext指針不為空 p2=p1; p1=p1-next; /p2指向原p1指向的結點p1后移一個結點 if(num=p1-id)/如果輸入的學生準考證號是p1所指的學號結點找到后刪除 if(p1=head) head=p1-next;/如果head指針和p1指針相等則將下一個結點賦給指針head else p2-next=p1-next;/否則將p1所指結點賦給p2所指結點將要刪除的學生信息跳過去 cout 刪除學號為num的學生n; n-;/將學生人數(shù)減1 return(head);/將頭指針返回 /查找學生信息函數(shù) student *Information:find(student *hea

15、d,long int num) /定義一個指向struct student的結構體指針函數(shù)*find()用來查找學生信息. if(head=NULL)/若調(diào)用次函數(shù)以前的頭指針head為空 coutid&p1-next!=NULL) /尋找結點當p1所指的學號不是輸入的學生學號并且p1所指的next指針不為空 p1=p1-next; /p1后移一個結點 if(num=p1-id)/如果要查找的學號是p1所指的學號 cout-n; cout學號 姓名 性別 院系 語文 英語 數(shù)學 C+ 平均分 總分 n; cout-n; coutsetw(8)id setw(9)name setw(8)sex

16、setw(13)score0 setw(16)score1 setw(10)score2 setw(9)score3 setw(6)total/4.0 setw(11)totalendl; cout-n; else cout 沒找到學號為num的學生.n; /結點沒找到 return(head); void Information:inorder(student *head) /定義inorder()函數(shù)將考生的總分從大到小排列并輸出 int i,k,m=0,j; student *p20;/定義一個指向struct student的結構體指針數(shù)組p if(head!=NULL)/如果頭指針是

17、空則繼續(xù) m=count(head); cout-n; cout學生成績統(tǒng)計表n; cout-n; cout學號 姓 名 性別 院系 語文 英語 數(shù)學 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)score

18、3 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 這是一個空表,請先輸入學生成績.n; else m=count(head); p1=head; for(k=0;kscore0; arg2+=p1-score1; arg3+=p1-score2; arg4+=p1-score3; p1=p1-next;

19、arg1/=m;arg2/=m;arg3/=m;arg4/=m; cout全班單科成績平均分n; cout-n; cout 語文平均分:setw(7)arg1 英語平均分:setw(7)arg2 數(shù)學平均分: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 scor

20、e2t score3t totalnext; student *Information:Read() /讀取函數(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ù)為空,請先輸入數(shù)據(jù)。endl; return 0; else cout 0;i-) p1=(student *)malloc(LEN); st.idst.sex st.score0st.score1st.score2st.score

21、3 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;/如果是輸入第一組學生考試信息就將指針p1賦給指針head else p2-next=p1;/否則將p1賦給p2所指結構體的next指針 p2=p1;/將指針p1賦給指針p2 n+; /將n的值加1 cout name

22、t /顯示讀入數(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 學生信息管理系統(tǒng)主菜單界面 *endl ; cout endl; coutendl; cout .輸入學生信息 endl; cout .顯示學生信息 endl; cout .排序統(tǒng)計成績 endl; cout .查找學生信息 endl; cout .增加學生信息 endl; cout .刪除學生信息 endl; cout .保存退出系統(tǒng) endl; coutendl; coutstr; if(atoi(str)7 | atoi(str)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論