




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、#include <stdio.h>#include <stdlib.h> #include <string.h> #inelude <conio.h>#define null 0 struct studentchar xuehao10;char name15j;char xingbie6;int nianling;int dianhua;char licence20;char address40j;char youxiang100;struct student *next;struct student *creat()/創(chuàng)建鏈表struct s
2、tudent *p,*head,*end;head=p=end=(struct student *)malloc(sizeof(struct student);/創(chuàng)建一個(gè)節(jié)點(diǎn) printf("=請(qǐng)輸入學(xué)生信息二=n");printfc請(qǐng)輸入學(xué)生學(xué)號(hào):”);scanf("%s",p->xuehao);while(strcmp(p->xuehao,m0m)!=0)end=p;printf(h 姓名:“);scanf(” s”,p->name);printf(”性別:“);scanf(m%s",p->xingbie);prin
3、tf("年齡:“);scanf(h%d'&p->nianling);printf(m 電話:“);scanf(n%d'&p->dianhua);printf(h 證件號(hào):“);scanf("%s",p->licence);printf(”家庭住址:“);scanf(h%s'*,p->address);printf(n 郵箱:“);scanf('*%s",p->youxiang);p=(struct student *)malloc(sizeof(struct student);
4、 end->next=p;/ en d=p;printfc*請(qǐng)輸入學(xué)生學(xué)號(hào):“); scanf(h%sh,p->xuehao);end->next=null;return head;void save(struct student *head)/保存鏈表為磁盤文件file *fp;struct student *p;char filename20;int ch;printf(m請(qǐng)輸入要保存的文件名:”);scanf("%s",filename);if(fp=fopen(filename,nrn)!=null)printfc*該文件已經(jīng)存在,是否覆蓋? nm
5、);printf(ml> 覆蓋.2、不覆蓋n“);scanf(” d“,&ch);if(ch!=l)printfc*請(qǐng)重新輸入要保存的文件名:”); scanf("%s",filename);if(fjp=fopen(filename,',w")=null)printfc*創(chuàng)建文件失敗!n”);return;/exit(0);正常退出,執(zhí)行后顯示 press anykey to continue; / getchar();p=head;while(p!=null)fprintf(fp,"%sn",p->xuehao)
6、;fprintf(fp/'%sn",p->name);fprintf(fp/'%sn",p->xingbie);fprintf(fp/'%dn'p->nianling);fprintf(fp,"%dn",p>dianhua);fpriihf(fpr%sn”,p>licence); fprintf(fp,"%sn",p->address); fprintf(fp/'%sn",p->youxiang); p=p->next;fputs(nov
7、erm,fp);printf(h文件保存成功!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)/doprintf(m學(xué)號(hào):%s'p->xuehao);printf(hn 姓名:%sm,p->name);printf(un 性別:%sn,p->xingbie);printf("n 年齡:%d&quo
8、t;,p->nianling);printf("n 電話:%d",p->dianhua);printf("n 證件號(hào):%s",p->iicence);printf(un 家庭地址:%sm,p->address);printf(unyouxiang: %sn",p->youxiang);p=p->next;/while(p!=null);getchar();struct student *openfile()/打開文件,即新創(chuàng)建鏈表讀取磁盤文件struct student *head,*p,*f;file *f
9、p;char filename20j;int ch;printfc'請(qǐng)輸入要打開的文件名:”);若文件保存在默認(rèn)路徑,讀取時(shí)無需輸入路徑scanf("%s",filename);if(fp=fopen(filename,nrm)=null)printf(”打開文件失敗!n”);printffk重新輸入文件名2、退出n“);scanf("%d'ch);if(ch=l)scanf(n %s ",filename);else if(ch=2)/getchar();/exit(o);return null;head=f=p=(struct stu
10、dent *)malloc(sizeof(struct student);fscanf(fp/,%s%s%s%d%d%s%s%sn,p->xuehao,p->name,p->xingbie?&p>nianling,&pdianhua, p->licence,p->address5p->youxiang);while(!feof(fp)p=(struct student *)malloc(sizeof(stnjct student);f->next=p;/節(jié)點(diǎn)連接fscanf(fp/'%s%s%s%d%d%s%s%s,p-&
11、gt;xuehao,p->name,p->xingbie,&p>nianling,&p>dianhua, p->licence,p->address,p->youxiang);if(strcmp(p->xuehao,novern)=0)f->next=null;printf(”文件打開成功,可顯示信息!n“);getchar();return head;)f=p;/ fclose(fp);/ f->next=null;/ return head;void sort_hao(struct student *head)/按
12、學(xué)號(hào)排序struct studentchar ch100;int i;p=f=t=head;if(head=null)printfc未打開任何文件!n”);getchar();return;/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);
13、strcpy(t->xuehao,f->xuehao);strcpy(f->xuehao,ch);strcpy(ch,t->name);strcpy(t->name5f- >n ame);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;
14、t->dianhua=f->dianhua;f->dianhua=i;strcpy(ch,t->licence);strcpy(t->licence,f->licence);strcpy(f->licence,ch);strcpy(ch,t->address);strcpy(t->address,f->address);strcpy(f->address,ch);strcpy(ch5t->youxicing); strcpy(t->youxiang,f->youxiang);strcpy(f->youxi
15、ang5ch);printf(”完成排序!n“);getchar();/ return head;/循環(huán)判斷,若此鏈表共有n個(gè)節(jié)點(diǎn),則共需進(jìn)行"2次循環(huán)判斷void sort_name(struct student *head)/按學(xué)生姓名排序struct studentchar ch100;int i;p=f=t=head;if(head=null)printf(”文件未能打開!n”);getchar();return;/void類型無返回值,可以用return結(jié)束子程序以返回主程序,但return絕不能帶回 任何值/ f=p->next;for(p=head:p->n
16、ext!=null;p=p->next)for(t=head,f=t->next;t->next!=null;t=t->next,f=f->next)/ rfl 于創(chuàng)建鏈表是以 p->xuehao=0 結(jié)束的故以f->next結(jié)束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-&
17、gt;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->dia nhua=f->dianhua; f->dianhua=i;strcpy(ch,t->iicence); strcpy(t->licence,f->
18、;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“); gelchar();/ retum head;void search(struct student 水head)/查詢 struct
19、 student *p;char str20;int i j=0;p=head;if(head=null)printf(”未打開任何文件! ”);getchar();return;/printf(hk按學(xué)號(hào)查詢2、按姓名查詢n”);scanf(” d",&i);if(i=l)printf(”請(qǐng)輸入學(xué)號(hào):“);elseprintfc*請(qǐng)輸入姓名:“);scanf(“s“,stq;while(p!=null)if(i=l)/按學(xué)號(hào)查詢,只輸岀一個(gè)結(jié)果,需保證學(xué)號(hào)不能重復(fù)if(strcmp(p->xuehao,str)=0)printf("學(xué)號(hào):%sn姓名:%sn性
20、別:%sn年齡:%dn電話:dn證件號(hào):%sn家庭地 址:%sn郵箱:%sn",p>xuehao,pname,pxingbie,p->nianling,pdianhua,p>liccnce,paddress,p>youx iang);j=l;break;if(i=2)/按姓名査詢,可輸出多個(gè)結(jié)果if(strcmp(p->name,str)=o)printf("學(xué)號(hào):sn姓名:sn性別:sn年齡:%dn電話:dn證件號(hào):sn家庭地 址:%sn郵箱:%sn",p>xuehao,pname,pxingbie,p->nianlin
21、g,pdianhua,p>liccnce,paddress,p>youx iang);j 二 1;p=p->next;getchar();/顯示查詢結(jié)果,沒有的話將一閃而過if(j=o)printf(”查找完畢,未搜到結(jié)果!n”);/ return;struct student *add(struct student *head)添加記錄struct studentif(head=null)printf(”未能打開任何文件!n”);getchar();return null;h=e=f=head;p=(struct student *)malloc(sizeof(struct
22、 student);/新添節(jié)點(diǎn)即新添加的記錄 printfc1 學(xué)號(hào):”);scanf(n%s",p->xuehao);printfc* 姓名:”);scanf("%s",p->name);printf("性別:”);scanf("%s",p->xingbie);printf(m 年齡:”);scanf("%d",&p->nianling);printfc* 電話:”);scanf(n%d'&p->dianhua);printfc'ffi 件號(hào):”);s
23、canf(h%sn,p->licence);printfc'家庭住址:”);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)/只有一個(gè)可用節(jié)點(diǎn)f->next=p;p->next=null;printf(”添加成功
24、!n”);return 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;elsee=e-> next;/仁 f->next;while(f->next!=null);if(f->next=null)f->next=p;p->next=null;printf(”添加成功!n”);return h;struct student *delet
25、e_mem(struct student *head)/刪除個(gè)人信息 struct student *p,*e;char strf20;if(head=null)printf(”未能打開任何文件!n”);getchar();return null;p=e=head;printf(h請(qǐng)輸入要?jiǎng)h除的學(xué)號(hào):”);scanf(” s",str);if(strcmp(p xuehao,str)=0)head=head->next;printf(n 刪除成功!n”);return head;p=p->next;while(p!二null)if(strcmp(p->xuehao,
26、str)=0)if(p->next!=null) e->next=p->next;if(p->next=null)e->next=null;printfc 刪除成功!n“);return head;p=p->next;e=e->next;printfc搜索完畢,未能找到結(jié)果!n“);return head;struct student *change(struct student *head)/修改記錄struct student *p;char str20j;if(head=null)printf(”未能打開任何文件!n”);getchar();re
27、turn null;p=head;printf("請(qǐng)輸入要修改的學(xué)生的學(xué)號(hào):”);scanf(n%s*str);while(p!=null)if(strcmp(p->xuehao,str)=0)printf(”學(xué)號(hào):%sn姓名:%sn性別:%sn年齡:%dn電話:%dn證件號(hào):%sn家庭地 址:%sn郵箱:%snm,p->xuehao,p->name,p->xingbie,p->nianling,p->dianhua,p->licence,p->address,p->youx iang);printfc'請(qǐng)按提示輸入修改后
28、的數(shù)據(jù)十);printfc'學(xué)號(hào):”);scanf("%s",p->xuehao);printf(h 姓名:”);scanf("%s",p->name);printf(h 性別:”);scanf("%s",p->xingbie);printf(m 年齡:”);scanf("%d",&p->nianling);printfc* 電話:”);scanf("%d",&p->dianhua);printfc'iie 件號(hào):”);scanf(&
29、quot;%s",p->licence);printfc'家庭住址:”); scanf("%s",p->address); printf(”郵箱:”); scanf("%s",p->youxiang); printfc 修改成功!n“); getchar();return head;p=p-> next;printfc'未能找到記錄!n”); return head;void mima()/創(chuàng)建密碼file *fp;char mimal20,mima220;int i=0;if(fp=fopen(,
30、9;mima","r")=null)printf(”密碼尚未創(chuàng)建!n”);getchar();doprintfc*請(qǐng)輸入密碼:”);scanf("%sm,mimal);printfc*請(qǐng)?jiān)俅屋斎朊艽a:“);scanf("%sm,mima2);if(strcmp(mima 1 ,mima2)!=0)printf(”兩次輸入的密碼不一樣,請(qǐng)重新輸入n”);i=l;)elsebreak;while(i);fp=fopen("mima','w");fprintf(fp,"%s",mimal);pr
31、intfc*密碼設(shè)置成功!n“); fclose(fp);getchar();return;elseprintf(”密碼已創(chuàng)建!n”);getchar();void delete_doc()file *fp;char mimal 20 ,mima2 20 ,fi lename20;printf(h請(qǐng)輸入初始化密碼:”); scanf("%su,mimal);fp=fopen(mmima","r");fscanf(fp,"%s",mima2);if(strcmp(mima 1 ,mima2)=0)printfc1請(qǐng)輸入要?jiǎng)h除的文件名:“
32、);scanf(h%sh,filename);if(remove(filename)=0)printfc 刪除成功!n“);getchar();return;elseprintfc*刪除失敗,請(qǐng)確認(rèn)是否存在此文件n”); getchar();return;elseprintf(”密碼錯(cuò)誤!n”);getchar();return;void output_use()printf(”使用方法如下:n");printfc'k編輯個(gè)人信息后需要保存,否則當(dāng)你再次啟用該功能時(shí)將覆蓋原來的信息.); printf(”2、保存信息后,若要在原文件中添加新的記錄,則首先應(yīng)啟動(dòng)/打開文件/功能,然 后啟動(dòng)/添加記錄/功能,添加完后保存an”);printf(”3、除了要新建文件外,若要進(jìn)行其他功能均需要先啟動(dòng)/打開文件/功能,才能繼續(xù), 否則進(jìn)行其他功能均不能對(duì)己有文件作任何改變.n”);printfc'4.編輯個(gè)人信息時(shí),以學(xué)號(hào)為零作為結(jié)束,故學(xué)生信息屮學(xué)號(hào)不能為零n”); prinht5、由于有些限制沒有編寫,故在保存前至少編輯一個(gè)有效的學(xué)生信息n”); printf("6、刪除文件前需保證已經(jīng)設(shè)置密碼,否則11!錯(cuò)!n”);getchar();void output_view() printf(h=nm); printf(ho> 使用說明n”);
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 地?zé)崮芾庙?xiàng)目場(chǎng)地調(diào)研服務(wù)費(fèi)用協(xié)議
- 口腔門診護(hù)士規(guī)劃方案
- 體育素養(yǎng)面試題及答案
- 溫州瑞南220千伏輸變電工程環(huán)境影響報(bào)告表
- 精裝修公寓水電費(fèi)分?jǐn)偣芾矸?wù)合同
- 公寓銷售外包方案
- 資質(zhì)工作考核方案
- 化工廠吊裝方案
- 涂裝安全考試題及答案
- 平邑幼教面試題及答案
- 風(fēng)力發(fā)電風(fēng)機(jī)基礎(chǔ)施工方案
- 專職消防隊(duì)和義務(wù)消防隊(duì)的組織管理制度
- 衛(wèi)生間防水補(bǔ)漏合同協(xié)議書模板
- 學(xué)校衛(wèi)生工作手冊(cè)
- 公租房運(yùn)營(yíng)管理服務(wù)方案(技術(shù)方案)
- 2024年初級(jí)消防設(shè)施操作員考試題庫(kù)800題(基礎(chǔ)知識(shí)+實(shí)操技能)
- 轉(zhuǎn)讓美容院店鋪合同
- YC/T 613-2024煙草企業(yè)有限空間作業(yè)安全技術(shù)規(guī)范
- 招標(biāo)售后服務(wù)方案及服務(wù)承諾
- 刮痧操作流程及評(píng)分標(biāo)準(zhǔn)
- 歇后語(yǔ)大全500條
評(píng)論
0/150
提交評(píng)論