


版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、流程圖:非法選項1.調用2.調用3.調用4.調用5.調用6.調用7.調用8.調用9.調用creat()dele()add()save)load(結束全局變量structstud(charname20;longnum;intage;charsex;intscore3;chartele12;structstud*next;子程序creat()函數功能:創建鏈表,提示輸入學生信息,儲存到鏈表中,錄入完成后輸入y繼續,輸入n停止,返回主菜單display()函數功能:顯示當前已經存入鏈表的信息dele()函數功能:刪除鏈表中學生信息,可按姓名或學號刪除add()函數功能:按學號插入學生信息modify
2、()函數功能:修改鏈表中學生信息search()函數功能:查找學生信息,可按學號或姓名查找sort()函數功能:對信息進行排序,可實現分別對三門成績排序save()函數功能:將鏈表中的數據保存到指定文件9.load()函數功能:將指定文件中已有的數據讀入鏈表源程序#include<stdio.h>#include<string.h>#include<stdlib.h>#include<conio.h>structstud(charname20;longnum;intage;charsex;intscore3;chartele12;structst
3、ud*next;main()(structstud*head;structstud*creat(void);voiddisplay(structstud*head);structstud*dele(structstud*head);structstud*add(structstud*head);structstud*modify(structstud*head);voidsearch(structstud*head);voidsave(structstud*head);structstud*sort(structstud*head);voidsave(structstud*head);stru
4、ctstud*load();charch;head=NULL;for(;)(clrscr();/*清屏函數*/printf(printf(nnttWelcometostudentinformationmanagementsystem");nnt*");printf(nttt1:printf(“nttt2:Listtheinformation");printf(“nttt3:Deletetheinformationprintf(“nttt4:Addtheinformation")printf(“nttt5:Modifytheinformationprint
5、f(“nttt6:Searchtheinformationprintf(“nttt7:Sorttheinformation")printf(“nttt8:Savetheinformation"printf(“nttt9:Loadtheinformation”printf(“nttt0:Exit);Entertheinformation););”);”);”);”);printf(ntttEnteryourchoice:”);fflush(stdin);ch=getchar();getchar();switch(ch)case1':head=creat();break
6、;case2':display(head);system(pause");break;case3':head=dele(head);system(pause");break;case4':head=add(head);system(pause");break;case5':head=modify(head);system(pause");break;case6':search(head);system(pause");break;case7':head=sort(head);system(paus
7、e");break;case8':save(head);system(pause");break;case9':head=load();break;case0':return;break;default:clrscr();printf(ntError!Pleasecheckyourinputnn");system(pause");structstud*creat(void)/*鏈表的創建*/structstud*head,*p1;charch;clrscr();head=NULL;p1=(structstud*)malloc(si
8、zeof(structstud);printf(tentername:");gets(p1->name);printf(tenternumber:");scanf(%ld",&p1->num);printf(tenterage:");scanf(%d",&p1->age);printf(tentersex:");fflush(stdin);scanf(%c",&p1->sex);printf(tenterMathscore:");scanf(%d",&
9、;p1->score0);printf(tenterEnglishscore:");scanf(%d",&p1->score1);printf(tenterCscore:");scanf(%d",&p1->score2);printf(tentertelephonenumber:");fflush(stdin);gets(p1->tele);head=p1;p1->next=NULL;do(printf(ntDOYOUWANTTOCONTINUE?YorN?”);printf(ntEnteryour
10、choise:");fflush(stdin);ch=getchar();clrscr();if(ch='y'|ch=Y)head=add(head);elseif(ch!='N'&&ch!='n')(printf(htError!Pleasecheckyourinput”);ch='y'while(ch=*'|ch=Y);return(head);structstud*dele(structstud*head)/*鏈表的刪除*/(structstud*p1,*p2;intchoose;longd
11、elnum;charname20;clrscr();printf(nttChoosethewayyouwant”);printf(nt1:Accordingtonamen);printf(nt2:Accordingtonumn”);printf(ntEnteryourchoice:”);scanf(%d”,&choose);fflush(stdin);if(choose=1)p1=head;(printf(ntEnterthename:”);gets(name);if(head=NULL)(printf(tnNoinformation!n");return(head);whi
12、le(strcmp(name,p1->name)!=0&&p1->next!=NULL)(p2=p1;p1=p1->next;if(strcmp(name,p1->name)=0)(if(p1=head)head=p1->next;elsep2->next=p1->next;printf(tDeleteSuccessed!nn”);elseprintf(tNotbeenfind!nn”);return(head);elseif(choose=2)printf(htEnterthenumber:”);scanf(%ld”,&del
13、num);if(head=NULL)printf(nNoinformation!n");return(head);p1=head;while(delnum!=p1->num&&p1->next!=NULL)p2=p1;p1=p1->next;if(delnum=p1->num)if(p1=head)head=p1->next;elsep2->next=p1->next;printf(tDeleteSuccessed!nn”);elseprintf(tNotbeenfind!n”);return(head);elseprintf
14、(ntError!Pleasecheckyourinputnn");return(head);voiddisplay(structstud*head)structstud*p;p=head;clrscr();if(head=NULL)printf(ntNoinformationnn”);elseprintf(nametnumbertagetsextMathtEnglishtCttelephonenumbern”);doprintf(%st%ldt%dt%ct%dt%dt%dt%sn",p->name,p->num,p->age,p->sex,p-&g
15、t;score0,p->score1,p->score2,p->tele);p=p->next;while(p!=NULL);structstud*add(structstud*head)/*鏈表的插入*/structstud*p1,*p2,*p0;p0=(structstud*)malloc(sizeof(structstud);clrscr();printf(nttInputtheinformation:”);printf(nttname:”);fflush(stdin);gets(p0->name);printf(ttnumber:”);scanf(%ld”
16、,&p0->num);printf(ttage:”);scanf(%d”,&p0->age);printf(ttsex:”);fflush(stdin);scanf(%c,&p0->sex);printf(ttMathscore:");scanf(%d”,&p0->score0);printf(ttEnglishscore:');scanf(%d”,&p0->score1);printf(ttCscore:”);scanf(%d”,&p0->score2);printf(tttelephone
17、number:”);fflush(stdin);gets(p0->tele);p1=head;if(head=NULL)head=p0;p0->next=NULL;elsewhile(p0->num>p1->num)p2=p1,p1=p1->next;if(p0->num<=p1->num)if(head=p1)head=p0;elsep2->next=p0;p0->next=p1;elsep1->next=p0;p0->next=NULL;return(head);structstud*modify(structs
18、tud*head)/*鏈表的修改*/structstud*p1,*p2,*p0;clrscr();printf(ntInputthestudentsname:”);p0=(structstud*)malloc(sizeof(structstud);fflush(stdin);gets(p0->name);if(head=NULL)printf(nNoinformation!nn");return(head);p1=head;while(strcmp(p0->name,p1->name)!=0&&p1->next!=NULL)p2=p1;p1=p
19、1->next;if(strcmp(p0->name,p1->name)=0)printf(nametnumbertagetsextMathtEnglishtCttelephonenumbern”);printf(%st%ldt%dt%ct%dt%dt%dt%sn",p1->name,p1->num,p1->age,p1->sex,p1->score0,p1->score1,p1->score2,p1->tele);if(p1=head)head=p1->next;elsep2->next=p1->n
20、ext;printf(tNewinformation:number:");scanf(%ld",&p0->num);printf(tttage:");scanf(%d",&p0->age);printf(tttsex:");fflush(stdin);scanf(%c",&p0->sex);printf(tttMathscore:");scanf(%d",&p1->score0);printf(tttEnglishscore:");scanf(%d&
21、quot;,&p1->score1);printf(tttCscore:");scanf(%d",&p1->score2);printf(ttttelephonenumber:");fflush(stdin);gets(p0->tele);p1=head;if(head=NULL)head=p0;p0->next=NULL;elsewhile(p0->num>p1->num)p2=p1;p1=p1->next;if(p0->num<=p1->num)if(head=p1)head=p
22、0;elsep2->next=p0;p0->next=p1;elsep1->next=p0;p0->next=NULL;printf(ModifySuccessed!nn”);elseprintf(Notbeenfind!nn”);return(head);voidsearch(structstud*head)/*查詢鏈表*/(structstud*p;intchoose;longnum;charname20;clrscr();printf(nttChoosethewayyouwant”);printf(nt1:Accordingtonamen);printf(nt2:
23、Accordingtonumn”);printf(ntEnteryourchoice:”);scanf(%d”,&choose);fflush(stdin);if(choose=1)(printf(ntenterthename:”);gets(name);if(head=NULL)(printf(tnNoinformation!nn");else(p=head;while(strcmp(name,p->name)!=0&&p->next!=NULL)(p=p->next;if(strcmp(name,p->name)=0)(printf
24、(nametnumbertagetsextMathtEnglishtCttelephonenumbern”);printf(%st%ldt%dt%ct%dt%dt%dt%sn",p->name,p->num,p->age,p->sex,p->score0,p->score1,p->score2,p->tele);elseprintf('Notbeenfind!nn”);elseif(choose=2)(printf(ntEnterthenumber:”);scanf(%ld”,&num);if(head=NULL)(pr
25、intf(hNoinformation!n”);else(p=head;while(num!=p->num&&p->next!=NULL)(p=p->next;if(num=p->num)(printf(nametnumbertagetsextMathtEnglishtCttelephonenumbern”);printf(%st%ldt%dt%ct%dt%dt%dt%sn",p->name,p->num,p->age,p->sex,p->score0,p->score1,p->score2,p->
26、;tele);elseprintf(tNotbeenfind!n”);elseprintf(ntError!Pleasecheckyourinputnn”);structstud*sort(structstud*head)(structstud*first;structstud*t;structstud*p;structstud*q;intch;clrscr();printf(httChoosethewayyouwant”);printf(nt1:AccordingtoMath:n”);printf(nt2:AccordingtoEnglishn”);printf(nt3:Accordingt
27、oCn”);printf(ntEnteryourchoice:”);scanf(%d”,&ch);first=head->next;head->next=NULL;while(first!=NULL)for(t=first,q=head;(q!=NULL)&&(q->scorech-1>t->scorech-1);p=q,q=q->next);first=first->next;if(q=head)head=t;elsep->next=t;t->next=q;printf(nttSuccess!n”);returnh
28、ead;voidsave(structstud*head)/*保存鏈表*/FILE*fp;structstud*p;charfilename20;printf(nninputthefilename:);fflush(stdin);gets(filename);if(fp=fopen(filename,”w”)=NULL)(printf(Savefile%serror!Typeitagain.nn”,filename);exit(0);p=head;while(p!=NULL)(fprintf(fp,”st”,p->name);fprintf(fp,”%ldt”,p->num);fp
29、rintf(fp,”%dt”,p->age);fprintf(fp,”%ct”,p->sex);fprintf(fp,”dt”,p->score0);fprintf(fp,”dt”,p->score1);fprintf(fp,”dt”,p->score2);fprintf(fp,”stn”,p->tele);p=p->next;printf(nttSuccess!n”);fclose(fp);structstud*load()/*鏈表的導入*/(FILE*fp;charfilename20;structstud*head,*p1,*p2;printf(nninputthefilename:);fflush(stdin);gets(filename);if(fp=fopen(filename,”r”)=NULL)(printf(Loadfile%serror!Typeitagain.nn”,filename);exit(0);if(!feof(fp)(head=(structstud*)malloc(sizeof(structstud);fscanf(fp,”st”,&a
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 中學考試試題及答案
- 云南省賓川縣四校2025屆物理高二下期末經典模擬試題含解析
- 云南省宣威市第十中學2024-2025學年高二生物第二學期期末經典試題含解析
- 云南省綠春縣一中2025屆高二下物理期末復習檢測試題含解析
- 云南省施甸縣第三中學2025年生物高二下期末質量跟蹤監視試題含解析
- 車展場地租賃及品牌合作營銷合同范本
- 遺產繼承權轉讓與執行合同
- 城市綜合體安保服務合同
- 科技研發園區場地使用與研發人員勞動保障合同
- 餐飲連鎖退伙合同范本
- 建設工程法規考試題真題及答案
- 2024年江蘇省泰興市事業單位公開招聘教師崗考試題帶答案分析
- Q-GDW 10393.1-2024 變電站設計規范-第1部分:35kV變電站
- 2025年市場營銷專業人才考核試題及答案
- 防范惡劣天氣安全教育
- 深圳市住房公積金管理中心員額人員招聘真題2024
- 梅州市大埔縣客家圍屋小學-攜數同行靜待花開-二年級下冊數學家長會【課件】
- MOOC 數字邏輯電路實驗-東南大學 中國大學慕課答案
- 國家開放大學《人文英語4》邊學邊練參考答案
- 法國“左岸派”電影課件
- AS9100D體系標準中文版
評論
0/150
提交評論