鏈表編寫學生信息管理系統(tǒng)_第1頁
鏈表編寫學生信息管理系統(tǒng)_第2頁
鏈表編寫學生信息管理系統(tǒng)_第3頁
鏈表編寫學生信息管理系統(tǒng)_第4頁
鏈表編寫學生信息管理系統(tǒng)_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、#include <stdio.h>#include <stdlib.h>#include <string.h>#include <conio.h>#define NULL 0struct student char xuehao10; char name15; char xingbie6; int nianling; int dianhua; char licence20; char address40; char youxiang100; struct student *next;struct student *creat()/創(chuàng)建鏈表 str

2、uct student *p,*head,*end; head=p=end=(struct student *)malloc(sizeof(struct student);/創(chuàng)建一個節(jié)點 printf("=請輸入學生信息=n"); printf("請輸入學生學號:"); scanf("%s",p->xuehao); while(strcmp(p->xuehao,"0")!=0) end=p; printf("姓名:"); scanf("%s",p->name

3、); printf("性別:"); scanf("%s",p->xingbie); printf("年齡:"); scanf("%d",&p->nianling); printf("電話:"); scanf("%d",&p->dianhua); printf("證件號:"); scanf("%s",p->licence); printf("家庭住址:"); scanf(&quo

4、t;%s",p->address); printf("郵箱:"); scanf("%s",p->youxiang); p=(struct student *)malloc(sizeof(struct student); end->next=p;/ end=p; printf("請輸入學生學號:"); scanf("%s",p->xuehao); end->next=NULL; return head;void save(struct student *head)/保存鏈表為磁

5、盤文件 FILE *fp; struct student *p; char filename20; int ch; printf("請輸入要保存的文件名:"); scanf("%s",filename); if(fp=fopen(filename,"r")!=NULL) printf("該文件已經(jīng)存在,是否覆蓋?n"); printf("1、覆蓋. 2、不覆蓋n"); scanf("%d",&ch); if(ch!=1) printf("請重新輸入要保存的文

6、件名:"); scanf("%s",filename); if(fp=fopen(filename,"w")=NULL) printf("創(chuàng)建文件失敗!n"); return;/exit(0);正常退出,執(zhí)行后顯示press anykey to continue; / getchar(); p=head; while(p!=NULL) fprintf(fp,"%sn",p->xuehao); fprintf(fp,"%sn",p->name); fprintf(fp,&qu

7、ot;%sn",p->xingbie); fprintf(fp,"%dn",p->nianling); fprintf(fp,"%dn",p->dianhua); fprintf(fp,"%sn",p->licence); fprintf(fp,"%sn",p->address); fprintf(fp,"%sn",p->youxiang); p=p->next; fputs("over",fp); printf("

8、;文件保存成功!n");/ getchar(); fclose(fp);void output(struct student *head)/輸出鏈表 struct student *p; p=head; if(p=NULL) printf("未創(chuàng)建任何記錄!n"); getchar(); return; /head; while(p!=NULL)/do printf("學號: %s",p->xuehao); printf("n姓名: %s",p->name); printf("n性別: %s"

9、,p->xingbie); printf("n年齡: %d",p->nianling); printf("n電話: %d",p->dianhua); printf("n證件號: %s",p->licence); printf("n家庭地址: %s",p->address); printf("nyouxiang: %sn",p->youxiang); p=p->next; /while(p!=NULL); getchar();struct student

10、*openfile()/打開文件,即新創(chuàng)建鏈表讀取磁盤文件 struct student *head,*p,*f; FILE *fp; char filename20; int ch; printf("請輸入要打開的文件名:");/若文件保存在默認路徑,讀取時無需輸入路徑 scanf("%s",filename); if(fp=fopen(filename,"r")=NULL) printf("打開文件失敗!n"); printf("1、重新輸入文件名 2、退出n"); scanf("

11、%d",ch); if(ch=1) scanf("%s",filename); else if(ch=2) /getchar(); /exit(0); return NULL; head=f=p=(struct student *)malloc(sizeof(struct student); fscanf(fp,"%s%s%s%d%d%s%s%s",p->xuehao,p->name,p->xingbie,&p->nianling,&p->dianhua,p->licence,p->ad

12、dress,p->youxiang); while(!feof(fp) p=(struct student *)malloc(sizeof(struct student); f->next=p;/節(jié)點連接 fscanf(fp,"%s%s%s%d%d%s%s%s",p->xuehao,p->name,p->xingbie,&p->nianling,&p->dianhua,p->licence,p->address,p->youxiang); if(strcmp(p->xuehao,"o

13、ver")=0) f->next=NULL; printf("文件打開成功,可顯示信息!n"); getchar(); return head; f=p; / fclose(fp);/ f->next=NULL;/ return head;void sort_hao(struct student *head)/按學號排序 struct student *p,*f,*t; char ch100; int i; p=f=t=head; if(head=NULL) printf("未打開任何文件!n"); getchar(); retur

14、n; /ok/ f=p->next; for(p=head;p->next!=NULL;p=p->next)/由P來控制循環(huán)次數(shù) for(t=head,f=t->next;t->next!=NULL;t=t->next,f=f->next) if(strcmp(t->xuehao,f->xuehao)>0) strcpy(ch,t->xuehao); strcpy(t->xuehao,f->xuehao); strcpy(f->xuehao,ch); strcpy(ch,t->name); strcpy(

15、t->name,f->name); strcpy(f->name,ch); strcpy(ch,t->xingbie); strcpy(t->xingbie,f->xingbie); strcpy(f->xingbie,ch); i=t->nianling; t->nianling=f->nianling; f->nianling=i; i=t->dianhua; t->dianhua=f->dianhua; f->dianhua=i; strcpy(ch,t->licence); strcpy(t

16、->licence,f->licence); strcpy(f->licence,ch); strcpy(ch,t->address); strcpy(t->address,f->address); strcpy(f->address,ch); strcpy(ch,t->youxiang); strcpy(t->youxiang,f->youxiang); strcpy(f->youxiang,ch); printf("完成排序!n"); getchar();/ return head;/循環(huán)判斷,若此鏈表共

17、有n個節(jié)點,則共需進行n2次循環(huán)判斷void sort_name(struct student *head)/按學生姓名排序 struct student *p,*f,*t; char ch100; int i; p=f=t=head; if(head=NULL) printf("文件未能打開!n"); getchar(); return;/void類型無返回值,可以用return結束子程序以返回主程序,但return絕不能帶回任何值 / f=p->next; for(p=head;p->next!=NULL;p=p->next) for(t=head,f

18、=t->next;t->next!=NULL;t=t->next,f=f->next)/由于創(chuàng)建鏈表是以p->xuehao=0結束的故以f->next結束 if(strcmp(t->name,f->name)>0) strcpy(ch,t->xuehao); strcpy(t->xuehao,f->xuehao); strcpy(f->xuehao,ch); strcpy(ch,t->name); strcpy(t->name,f->name); strcpy(f->name,ch); str

19、cpy(ch,t->xingbie); strcpy(t->xingbie,f->xingbie); strcpy(f->xingbie,ch); i=t->nianling; t->nianling=f->nianling; f->nianling=i; i=t->dianhua; t->dianhua=f->dianhua; f->dianhua=i; strcpy(ch,t->licence); strcpy(t->licence,f->licence); strcpy(f->licence,

20、ch); strcpy(ch,t->address); strcpy(t->address,f->address); strcpy(f->address,ch); strcpy(ch,t->youxiang); strcpy(t->youxiang,f->youxiang); strcpy(f->youxiang,ch); printf("完成排序!n"); getchar();/ return head;void search(struct student *head)/查詢 struct student *p; char

21、str20; int i,j=0; p=head; if(head=NULL) printf("未打開任何文件!"); getchar(); return;/ printf("1、按學號查詢 2、按姓名查詢n"); scanf("%d",&i); if(i=1) printf("請輸入學號:"); else printf("請輸入姓名:"); scanf("%s",str); while(p!=NULL) if(i=1)/按學號查詢,只輸出一個結果,需保證學號不能重復

22、 if(strcmp(p->xuehao,str)=0) printf("學號: %sn姓名: %sn性別: %sn年齡: %dn電話: %dn證件號: %sn家庭地址: %sn郵箱: %sn",p->xuehao,p->name,p->xingbie,p->nianling,p->dianhua,p->licence,p->address,p->youxiang); j=1; break; if(i=2)/按姓名查詢,可輸出多個結果 if(strcmp(p->name,str)=0) printf("學

23、號: %sn姓名: %sn性別: %sn年齡: %dn電話: %dn證件號: %sn家庭地址: %sn郵箱: %sn",p->xuehao,p->name,p->xingbie,p->nianling,p->dianhua,p->licence,p->address,p->youxiang); j=1; p=p->next; getchar();/顯示查詢結果,沒有的話將一閃而過 if(j=0) printf("查找完畢,未搜到結果!n");/ return;struct student *add(struct

24、 student *head)/添加記錄 struct student *p,*e,*f,*h; if(head=NULL) printf("未能打開任何文件!n"); getchar(); return NULL; h=e=f=head; p=(struct student *)malloc(sizeof(struct student);/新添節(jié)點即新添加的記錄 printf("學號:"); scanf("%s",p->xuehao); printf("姓名:"); scanf("%s"

25、,p->name); printf("性別:"); scanf("%s",p->xingbie); printf("年齡:"); scanf("%d",&p->nianling); printf("電話:"); scanf("%d",&p->dianhua); printf("證件號:"); scanf("%s",p->licence); printf("家庭住址:");

26、 scanf("%s",p->address); printf("郵箱:"); scanf("%s",p->youxiang); if(strcmp(f->xuehao,p->xuehao)>0)/和表頭比較 p->next=f; h=p; printf("添加成功!n"); return h; if(f->next=NULL)/只有一個可用節(jié)點 f->next=p; p->next=NULL; printf("添加成功!n"); retur

27、n h; do/while(f->next!=NULL) f=f->next; if(strcmp(f->xuehao,p->xuehao)>0) e->next=p; p->next=f; printf("添加成功!n"); return h; else e=e->next;/ f=f->next; while(f->next!=NULL); if(f->next=NULL) f->next=p; p->next=NULL; printf("添加成功!n"); return

28、h; struct student *delete_mem(struct student *head)/刪除個人信息 struct student *p,*e; char str20; if(head=NULL) printf("未能打開任何文件!n"); getchar(); return NULL; p=e=head; printf("請輸入要刪除的學號:"); scanf("%s",str); if(strcmp(p->xuehao,str)=0) head=head->next; printf("刪除成功

29、!n"); return head; p=p->next; while(p!=NULL) if(strcmp(p->xuehao,str)=0) if(p->next!=NULL) e->next=p->next; if(p->next=NULL) e->next=NULL; printf("刪除成功!n"); return head; p=p->next; e=e->next; printf("搜索完畢,未能找到結果!n"); return head;struct student *cha

30、nge(struct student *head)/修改記錄 struct student *p; char str20; if(head=NULL) printf("未能打開任何文件!n"); getchar(); return NULL; p=head; printf("請輸入要修改的學生的學號:"); scanf("%s",str); while(p!=NULL) if(strcmp(p->xuehao,str)=0) printf("學號: %sn姓名: %sn性別: %sn年齡: %dn電話: %dn證件號:

31、 %sn家庭地址: %sn郵箱: %sn",p->xuehao,p->name,p->xingbie,p->nianling,p->dianhua,p->licence,p->address,p->youxiang); printf("請按提示輸入修改后的數(shù)據(jù)n"); printf("學號:"); scanf("%s",p->xuehao); printf("姓名:"); scanf("%s",p->name); printf

32、("性別:"); scanf("%s",p->xingbie); printf("年齡:"); scanf("%d",&p->nianling); printf("電話:"); scanf("%d",&p->dianhua); printf("證件號:"); scanf("%s",p->licence); printf("家庭住址:"); scanf("%s"

33、;,p->address); printf("郵箱:"); scanf("%s",p->youxiang); printf("修改成功!n"); getchar(); return head; p=p->next; printf("未能找到記錄!n"); return head;void mima()/創(chuàng)建密碼 FILE *fp; char mima120,mima220; int i=0; if(fp=fopen("mima","r")=NULL) pri

34、ntf("密碼尚未創(chuàng)建!n"); getchar(); do printf("請輸入密碼:"); scanf("%s",mima1); printf("請再次輸入密碼:"); scanf("%s",mima2); if(strcmp(mima1,mima2)!=0) printf("兩次輸入的密碼不一樣,請重新輸入n"); i=1; else break; while(i); fp=fopen("mima","w"); fprintf(

35、fp,"%s",mima1); printf("密碼設置成功!n"); fclose(fp); getchar(); return; else printf("密碼已創(chuàng)建!n"); getchar();void delete_doc() FILE *fp; char mima120,mima220,filename20; printf("請輸入初始化密碼:"); scanf("%s",mima1); fp=fopen("mima","r"); fscanf

36、(fp,"%s",mima2); if(strcmp(mima1,mima2)=0) printf("請輸入要刪除的文件名:"); scanf("%s",filename); if(remove(filename)=0) printf("刪除成功!n"); getchar(); return; else printf("刪除失敗,請確認是否存在此文件.n"); getchar(); return; else printf("密碼錯誤!n"); getchar(); retur

37、n;void output_use() printf("使用方法如下:n"); printf("1、編輯個人信息后需要保存,否則當你再次啟用該功能時將覆蓋原來的信息.n"); printf("2、保存信息后,若要在原文件中添加新的記錄,則首先應啟動/打開文件/功能,然后啟動/添加記錄/功能,添加完后保存.n"); printf("3、除了要新建文件外,若要進行其他功能均需要先啟動/打開文件/功能,才能繼續(xù),否則進行其他功能均不能對已有文件作任何改變.n"); printf("4、編輯個人信息時,以學號為零

38、作為結束,故學生信息中學號不能為零n"); printf("5、由于有些限制沒有編寫,故在保存前至少編輯一個有效的學生信息n"); printf("6、刪除文件前需保證已經(jīng)設置密碼,否則出錯!n"); getchar();void output_view() printf("=n"); printf("0、使用說明n"); printf("1、編輯學生信息n"); printf("2、保存學生信息n"); printf("3、顯示學生信息n"); printf("4、打開記錄n"); printf("5、將記錄排序n"); printf("6、查詢記錄n"); printf("

溫馨提示

  • 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

提交評論