




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、運行結果:程序源碼:#include#include#include#include#include#defineLENsizeof(structstudent)/求字節數運算符structstudentcharname20;longintnum;charsex4;intage;charaddress30;floatscore;structstudent*next;/鏈表;/定義一個結構題intTOTAL_NUM=0;/學生總數structstudent*head=NULL;voidmainmenu();/主界面voidrecord();/記錄數據voidinsert(structstuden
2、t*stu);/插入數據voiddisplay(structstudent*stu);/顯示一個學生的信息voiddisplayAll();/顯示所有學生的信息voidquery();/查詢學生信息voidquery_by_num();/按學號查詢學生信息voidquery_by_name();voidreadData();/讀取文件里學生的信息voidwriteData();/向文件寫入學生信息voidfreeAll();/清空鏈表內容voiddel();/刪除學生信息voidchange();/更改學生信息voidsort();/排序voiddevise(structstudent*p);
3、/選擇更改內容intmain(void)mainmenu();return0;/系統主菜單voidmainmenu()intchoice;choice=-1;readData();printf(tttn);printf(ttt|歡迎使用通信工程專業學生信息管理系統|n);printf(tttn);printf(ttt本程序需要在當前目錄下建立student.txt才可正常運行n);doprintf(nnn);printf(tttn);printf(ttt通信工程專業學生信息管理系統|n);printf(tttn);printf(ttt1錄入學生信息|n);printf(ttt2瀏覽學生信息|n
4、);printf(ttt3查詢學生信息|n);printf(ttt4刪除學生信息|n);printf(ttt5修改學生信息|n);printf(ttt6排序|n);printf(ttt0退出系統|n);n);printf(tttprintf(請輸入您的選擇);scanf(%d,&choice);switch(choice)case0:writeData();freeAll();exit(0);case1:record();break;case2:displayAll();break;case3:query();break;case4:del();break;case5:change();bre
5、ak;case6:sort();break;default:printf(n無效選項!);break;while(choice!=0);/錄入學生信息voidrecord()structstudent*p0;p0=(structstudent*)malloc(LEN);printf(ttt請輸入學生的姓名:);scanf(%s,p0-name);printf(ttt請輸入學生的學號:);scanf(%ld,&p0-num);printf(ttt請輸入學生的性別:);scanf(%s,p0-sex);printf(ttt請輸入學生的年齡:);scanf(%d,&p0-age);printf(tt
6、t請輸入學生的地址:);scanf(%s,p0-address);printf(ttt請輸入學生的成績:);scanf(%f,&p0-score);insert(p0);printf(ttt該學生的信息為:n);printf(tttn);printf(ttt姓名t學號tt年齡t性別t地址tt成績n);display(p0);voidinsert(structstudent*stu)structstudent*p0,*p1,*p2;p1=head;p0=stu;if (head = NULL)head=p0;p0-next=NULL;elsewhile(p0-nump1-num)&(p1-nex
7、t!=NULL)p2=p1;p1=p1-next;if(p0-numnum)if(head=p1)head=p0;elsep2-next=p0;p0-next=p1;elsep1-next=p0;p0-next=NULL;TOTAL_NUM+;voiddisplay(structstudent*p)printf(ttt%st%ldtt%dt%st%stt%fn,p-name,p-num,p-age,p-sex,p-address,p-score);/瀏覽學生信息voiddisplayAll()structstudent*p;printf(ttt學生總數:%dn,TOTAL_NUM);p=hea
8、d;if(head!=NULL)printf(ttt姓名t學號tt年齡t性別t地址tt成績n);printf(tttn);dodisplay(p);p=p-next;while(p!=NULL);printf(n);voidquery()intchoice;choice=-1;doprintf(n);printf(n);printf(|按學號查詢請按1|n);printf(|按姓名查詢請按2|n);printf(|取消請按0|n);printf(+n);printf(請輸入您的選擇);scanf(%d,&choice);switch(choice)case0:return;case1:quer
9、y_by_num();break;case2:query_by_name();break;default:printf(n無效選項!);break;while(choice!=0);/按姓名查詢學生信息voidquery_by_name()charname20;structstudent*p1;printf(請輸入學生的姓名);scanf(%s,name);if(head=NULL)printf(無學生記錄n);return;p1=head;while(strcmp(name,p1-name)&p1-next!=NULL)p1=p1-next;if(!strcmp(name,p1-name)p
10、rintf(ttt姓名t學號tt年齡t性別t地址tt成績n);printf(tttAn);display(pl);elseprintf(沒有該學生記錄請核對”);/按學號查詢學生信息voidquery_by_num()intnum;structstudent*p1;printf(請輸入學生的學號);scanf(%ld,&num);if(head=NULL)printf(無學生記錄n);return;p1=head;while(num!=p1-num&p1-next!=NULL)pl=p1-next;if(num=p1-num)printf(ttt姓名t學號tt年齡t性別t地址tt成績n);pr
11、intf(tttAn);display(p1);elseprintf(ttt沒有該學生記錄請核對);/寫入文件voidwriteData()FILE*fp;文件指針structstudent*p;fp=fopen(1.txt,w);if(!fp)printf(文件打開錯誤);return;fprintf(fp,%dn,TOTAL_NUM);for(p=head;p!=NULL;p=p-next)fprintf(fp,%st%ldt%st%dt%st%fn,p-name,p-num,p-sex,p-age,p-address,p-score);fclose(fp);voidfreeAll()st
12、ructstudent*p1,*p2;p1=p2=head;while(p1)p2=p1-next;free(p1);p1=p2;/讀取文件voidreadData()FILE*fp;/文件指針structstudent*p1,*p2;fp=fopen(student.txt,r);if(!fp)printf(文件打開錯誤);return;fscanf(fp,%dn,&TOTAL_NUM);head=p1=p2=(structstudent*)malloc(LEN);fscanf(fp,%st%ldt%st%dt%st%fn,p1-name,&p1-num,p1-sex,&p1-age,p1-
13、address,&p1-score);while(!feof(fp)p1=(structstudent*)malloc(LEN);fscanf(fp,%st%ldt%st%dt%st%fn,p1-name,&p1-num,p1-sex,&p1-age,p1-address,&p1-score);p2-next=p1;p2=p1;p2-next=NULL;fclose(fp);/刪除學生信息voiddel()structstudent*p1,*p2;longintnum;if(head=NULL)printf(無學生記錄n);return;printf(請輸入您要刪除的學生的學號”);scanf
14、(%ld,&num);p1=head;while(num!=p1-num&p1-next!=NULL)p2=p1;p1=p1-next;if(num=p1-num)if(p1=head)head=p1-next;elsep2-next=p1-next;free(p1);TOTAL_NUM-;elseprintf(沒有該學生記錄請核對n);voidsort()/排序模塊。將學生記錄按學號從小到大排列。用起泡排序算法實現inti;structstudent*ptr,*s=head,*p;intcount=0,count1;while(s)/統計鏈表結點個數count+;s=s-next;for(i
15、=1;inext&(count1-)if(ptr-scoreptr-next-score)s=ptr-next;ptr-next=s-next;if(p=NULL)/ptr處于隊頭時head=s;elsep-next=s;s-next=ptr;p=s;elseptr=ptr-next;if(p=NULL)/ptr處于隊頭時p=head;elsep=p-next;displayAll();return;voidchange()structstudent*p1,*p2;longintnum;if(head=NULL)printf(無學生記錄n);return;printf(請輸入您要修改的學生的學
16、號);scanf(%ld,&num);p1=head;while(num!=p1-num&p1-next!=NULL)p2=p1;p1=p1-next;if(num=p1-num)devise(p1);elseprintf(沒有該學生記錄請核對n);voiddevise(structstudent*p)intchoice;choice=-1;doprintf(請選擇您要修改的學生的信息內容n);printf(+n);printf(|姓名請按1|n);printf(|學號請按2|n);printf(|性別請按3|n);printf(|年齡請按4|n);printf(|地址請按5|n);printf(|愛好請按6|n);printf(|取消請按0|n);printf(+n);printf(請輸入您的選擇);scanf(%d,&choice);switch(choice)case0:return;case1:printf(請輸入新姓名);scanf(%s,p-name);break;case2:prin
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 加強農村基層黨組織紀律建設的路徑與對策
- 把握健康消費新機遇的策略及實施路徑
- 東西方文化講課件
- 演講技巧教學課件
- 腫瘤基因表達調控-洞察及研究
- 長江工程職業技術學院《商業演出策劃與實踐》2023-2024學年第二學期期末試卷
- 廣西工業職業技術學院《和聲一》2023-2024學年第二學期期末試卷
- 哈爾濱幼兒師范高等專科學校《客戶關系管理》2023-2024學年第二學期期末試卷
- 山東工藝美術學院《高等代數一》2023-2024學年第二學期期末試卷
- 干細胞肝損傷修復-洞察及研究
- (2025)入黨積極分子培訓考試試題及答案
- 2025年計算機網絡技術考試試卷及答案
- 2025年天津市河西區中考二模語文試題
- 教育事業十五五(2026-2030)發展規劃
- 2025年中醫基礎理論考試試題及答案
- 2025中國鐵路濟南局集團限公司招聘116人(七)易考易錯模擬試題(共500題)試卷后附參考答案-1
- 酒店入股合同協議書范本
- 2025年高考軍隊院校征集和招錄人員政治考核表(原表)
- TCCEAS001-2022建設項目工程總承包計價規范
- 思想道德與法治(湖南師范大學)智慧樹知到期末考試答案章節答案2024年湖南師范大學
- 振型中的節點,節線,節徑和節圓
評論
0/150
提交評論