自己做的分文件學(xué)生信息管理系統(tǒng)_第1頁
自己做的分文件學(xué)生信息管理系統(tǒng)_第2頁
自己做的分文件學(xué)生信息管理系統(tǒng)_第3頁
自己做的分文件學(xué)生信息管理系統(tǒng)_第4頁
自己做的分文件學(xué)生信息管理系統(tǒng)_第5頁
已閱讀5頁,還剩9頁未讀 繼續(xù)免費(fèi)閱讀

付費(fèi)下載

下載本文檔

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

文檔簡介

1、#i nclude"stud_mgr_system.h" int main( void)char opt;DoubleL ink head = NULL;DoubleLi nk findnode = NULL;char findnu m10;secrecy();while(1)system("color OA");menu();prin tf("n");printf("t請輸入要操作的編號【1-8】:bb");scan f("%c", & opt);if(opt = 'n'

2、; | opt = '0')prin tf("ttt");printf("nnn不能輸入回車鍵或空格!nnn");else if(opt > '8' | opt < '1')prin tf("ttt");printf("nnn 輸入錯誤!請輸入【1-8】: nnnn "); system("PAUSE");system("CLS");switch(opt)case '1':head = creatdo

3、ubleli nk();head = save_file(head);break;case '2':system("CLS");prin tlist(head);system("PAUSE"); system("CLS"); break;case 3:system("CLS");printf("請輸入要查找學(xué)生的學(xué)號=>");scan f("%s", &findn um);findnode = findin fo(head, findnu m);

4、if(!findno de)printf("nn 沒有找到!n");system("PAUSE");system("CLS");break;case 4:system("CLS");head = add no de(head);printf("n*新增之后的鏈表 *n");prin tlist(head);prin tf("n*n");system("PAUSE");system("CLS");head = save_file(head

5、);break;case '5':system("CLS");if(head = NULL)printf("當(dāng)前的鏈表為空!沒有要刪除的信息! break;head = delete no de(head);save_file(head);break;nn");case '6':if(head = NULL)nn");printf("nn當(dāng)前鏈表為空!沒有要修改的信息system("PAUSE");break;head = modify in fo(head);system(&quo

6、t;PAUSE");system("CLS");break;case 7':freelist(head);system("PAUSE");system("CLS");save_file(head);break;case 8:system("color 5B");system("CLS");prin tf("nnnnnnnnn");printf("ttt 謝謝使用!再見! ! nnnnnnn"); exit(0);break;/defaul

7、t: printf("輸入錯誤!請重新輸入 !n");head = save_file(head);return 0;#i nclude"stud_mgr_system.h"/*錯誤*/void prin t_err(char *p)perror("p");exit(1);/*輸出鏈表信息*/void prin tlist(DoubleL ink L)/FILE *fp;/struct stud_mgr_sys stude nt;DoubleL ink tmp;tmp = L;/*if(fp = fope n( "E:stu

8、d_mgr_system.txt", "r") = NULL) prin tf("nF ail to ope n E:stud_mgr_system.txt!n"); getchar();exit(1);*/*if(fread(tmp,sizeof(struct stud_mgr_sys),1,fp) != 1 ) prin tf("Fail to read E:stud_mgr_system.txt!n"); getchar();elsewhile(tmp != NULL)%sn", tmp->nu m);

9、%sn", tmp->n ame);%sn", tmp->pho ne);%sn", tmp->addr);printf("學(xué)生的學(xué)號 printf("學(xué)生的姓名 printf("學(xué)生的電話 printf("學(xué)生的地址 prin tf("n");tmp=tmp->fro nt;fclose(fp);*/while(tmp != NULL)printf("學(xué)生的學(xué)號 printf("學(xué)生的姓名 printf("學(xué)生的電話 printf("學(xué)生的

10、地址 prin tf("n");%sn", tmp->nu m);%sn", tmp->n ame);%sn", tmp->ph on e);%sn", tmp->addr);tmp=tmp->fr ont;/*清空鏈表*/void freelist(DoubleL ink L)DoubleL ink ptr;while(L != NULL)ptr = L;L = L->fro nt;free(ptr);prin tf("nnnn");printf("ttt 鏈表清空完

11、畢!nnn");/*雙鏈表的創(chuàng)建*/DoubleL ink creatdoubleli nk()DoubleL ink head;DoubleL ink new_no de, before;int coun t, i;head = (DoubleL in k)malloc(sizeof(DoubleL in k);if(!head)prin t_err("Fail to malloc head");head = NULL;before = head;printf("請輸入要創(chuàng)建鏈表節(jié)點(diǎn)的個數(shù)=>");scan f("%d&quo

12、t;, &count);for(i = 1; i <= count; i+)new_node = (DoubleLi nk)malloc(sizeof(DoubleLi nk); if(!new_no de)prin t_err("Fail to malloc new_no de");printf("請輸入第 %d個學(xué)生的學(xué)號 =>",i); sca nf("%s", &new_no de->nu m);/gets (new_no de->nu m);printf("請輸入第 %d個學(xué)

13、生的姓名 =>",i); sca nf("%s", &new_no de->n ame);/gets (new_no de->n ame);printf("請輸入第 d個學(xué)生的電話 =>",i); sea nf("%s", &new_no de->ph on e);/gets (new_no de->ph on e);printf("請輸入第 %d個學(xué)生的地址 =>",i); sca nf("%s", &new_no d

14、e->addr);/gets (new_no de->addr);prin tf("n");new_no de->fr ont = NULL;if(head = NULL)head = new_no de; before = head;elsebefore->front = new_no de; new_no de->back = before;before = new_no de;printf("鏈表創(chuàng)建成功!nn");system("PAUSE");system("CLS");re

15、tur n head;/*增加學(xué)生的信息*/DoubleLink add node(DoubleLink L)DoubleL ink add new, end;end = L;add new = (DoubleLi nk)malloc(sizeof(DoubleLi nk); if(!add new)prin t_err("Fail to malloc add new");printf("請輸入要插入的學(xué)生的學(xué)號=>");sca nf("%s", &add new->nu m);printf("請輸入要插

16、入的學(xué)生的姓名=>");sca nf("%s", &add new->n ame);printf("請輸入要插入的學(xué)生的電話=>");sca nf("%s", &add new->ph on e);printf("請輸入要插入的學(xué)生的地址=>");scan f("%s", &add new->addr); add new->fro nt = NULL;if(L = NULL)L = add new;else while(

17、e nd->fro nt != NULL) end = en d->fr ont;en d->fr ont = add new; addnew->back = end;printf("nn該學(xué)生的信息插入完畢!nn");return L;/*學(xué)生信息的刪除*/DoubleL ink delete no de(DoubleL ink L)DoubleL ink ptr, tail;tail = L;while(tail->fro nt != NULL)tail = tail->fr ont;char deln ame10;printf(&q

18、uot;請輸入要刪除學(xué)生的學(xué)號=>");scan f("%s", &del name);if(fin di nfo(L, deln ame) = NULL)printf("n刪除失敗!沒有這個節(jié)點(diǎn)的信息!n");exit(1);printf("n=你刪除的學(xué)生的信息為=nn"); ptr = findin fo(L, deln ame);prin tf("n=nn"); printf("tt 刪除成功! nn");system("PAUSE");if(

19、ptr = L)return L->fro nt; else if(tail = ptr) tail->fro nt = NULL;elseptr->back->fr ont = ptr->fr ont; ptr->fr on t->back = ptr->back;return L;/*查詢學(xué)生的信息*/DoubleLi nk fin di nfo(DoubleLi nk L, char findnu m)int i = 1;DoubleL ink ptr;ptr = L;while(ptr != NULL)if(strcmp(ptr- >

20、;num, findnum) = 0)printf("n這個學(xué)生在鏈表的第%d個位置。nn”, i);prin tf("n=nn"); printf("這個學(xué)生的學(xué)號為:%sn", ptr->num);printf("這個學(xué)生的姓名為:%sn", ptr->name);printf("這個學(xué)生的電話為:%sn", ptr->phone);printf("這個學(xué)生的地址為:%sn", ptr->addr);prin tf("nn=nn"); r

21、eturn ptr;elseptr = ptr->fro nt;i+;return ptr;/*將內(nèi)容存到文件中*/DoubleL ink save_file(DoubleL ink L) FILE *fp;/struct stud_mgr_sys stude nt;DoubleL ink ptr;ptr = L;if(fp = fope n("E:stud_mgr_system.txt", "ab+") = NULL)prin tf("Fail to ope n E:stud_mgr_system.txt!n");getcha

22、r();exit(1);while(ptr != NULL)if(fwrite(ptr, sizeof(struct stud_mgr_sys), 1, fp) != 1)prin tf("Fail to write file!n");getchar();exit(1);ptr = ptr->fr ont;printf("nnn 文件保存完畢!nnn");return L;/*學(xué)生信息的修改*/DoubleLi nk modifyi nfo(DoubleLi nk L)DoubleL ink modptr;char modnu m10;printf

23、("請輸入要修改學(xué)生信息的學(xué)號=>");scan f("%s", & mod num);modptr = findin fo(L, modnu m);if(modptr = NULL)printf("nn沒有找到該學(xué)生的信息!修改失?。?nn"); printf("請輸入學(xué)號 =>");sca nf("%s", &modptr- >nu m);printf("請輸入姓名 =>");sca nf("%s", &

24、modptr- >n ame);printf("請輸入電話 =>");sca nf("%s", &modptr->ph on e);printf("請輸入地址 =>");scan f("%s", & modptr->addr);printf("nn 修改成功!nn");return L;/*菜單選項表*/void menu()prin tf("nn");printf("t :=學(xué)生信息管理系nn );prin tf(&q

25、uot;t* MENU *n")prin tf("t*n"):prin tf("t*1創(chuàng)建學(xué)生信息*2.顯示學(xué)生信息*n");prin tf("t*3查找學(xué)生信息*4新增學(xué)生信息*n");prin tf("t*5刪除學(xué)生信息*6.修改學(xué)生信息*n");prin tf("t*7學(xué)生信息清空*8.退出管理系統(tǒng)*n");prin tf("t*n"):prin tf("t*n")*);prin tf("t*|prin tf("t*n&

26、quot;) /*密碼*/void secrecy()char in itsec1O = "123456"char in putsec1O;int i, j = 0;nn");printf("n你共有三次機(jī)會輸入密碼以進(jìn)入系統(tǒng)!for(i = 3; i >= 1; -i)prin tf("tt");printf("nn請輸入密碼以進(jìn)入系統(tǒng):"); scan f("%s", &n putsec);if(strcmp(i nitsec, in putsec) != 0)printf(&

27、quot;nn 密碼輸入錯誤!你還有 %d 次機(jī)會! nnnnnnnnn”,i - 1);+j;system("PAUSE");system("CLS");elsebreak;if(j = 3)printf("程序即將退出!nn");system("pause");exit(1);system("CLS");system("color 3A");prin tf("nnnn");prin tf("tt=歡迎使用學(xué)生管理系統(tǒng)=n");pri

28、n tf("tt=n");prin tf("tt=n");prin tf("tt=n");n");prin tf("nnnnnnnnnnn"); system("PAUSE"); system("CLS");system("CLS");/*密碼修改函數(shù)*/*void cha ngesec()char n ewsec10;char suresec10;printf("請輸入原來的密碼=>");sca nf("%s", &suresec);if(strcmp(i nitsec, suresec) != 0)printf("密碼輸入錯誤!請重新輸入原來密碼以改密碼!n");printf("請輸入原來的密碼=>");sca nf("

溫馨提示

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

最新文檔

評論

0/150

提交評論