C語言程序設計報告_第1頁
C語言程序設計報告_第2頁
C語言程序設計報告_第3頁
C語言程序設計報告_第4頁
C語言程序設計報告_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、 .wd. .wd. .wd.二一一年 九 月設計要求題目三 通訊錄管理系統(tǒng)任務:自學C語言中相關知識,設計出通訊錄管理系統(tǒng)。要求如下所述:建設通訊錄信息,信息至少包含編號、姓名、年齡、 、通訊地址、電子郵箱等;能夠提供添加、刪除和修改通訊錄信息的功能,并給出確認是否保存或刪除記錄的提示信息;能夠提供按姓名或 等查詢并顯示相應記錄信息;將通訊錄保存在文件中;能夠按表格方式輸出通訊錄信息。二、要求為了保證所有的數(shù)據(jù)可以長期被使用,要求程序能將相關數(shù)據(jù)存儲在外部數(shù)據(jù)文件中,具體數(shù)據(jù)格式和文件名、路徑等自定;根據(jù)所設計的算法,定義相應函數(shù)分別實現(xiàn)系統(tǒng)的各子功能模塊,同時由主程序提供友好的用戶界面,使

2、用戶可通過選擇主菜單來調用課程設計中要求完成的各個功能模塊,子程序執(zhí)行完后可返回到主菜單,繼續(xù)選擇其他功能執(zhí)行。源程序要求書寫標準,構造清晰。重點函數(shù)的重點變量,重點功能局部均要求給出清晰的程序注釋。程序編譯、鏈接成功后,自己設計實現(xiàn)程序功能的一組或多組測試數(shù)據(jù),并嚴格按照此測試數(shù)據(jù)進展測試,然后分析測試結果。如果程序不能正常運行或結果不正確,那么需對程序進展單步調試,在調試過程中認真查找算法實現(xiàn)中存在的問題,并加以分析和修正。程序詳解首先,定義構造體struct studentlong num;/用于存儲學號char name20;/姓名int age;/年齡long telephone;/

3、 號碼char adress40;/地址char E_mail30;/郵箱int QQ12;/增設的QQ一欄struct student *next;/用于存放下一級指針first;first為第一個節(jié)點,繼而在其后動態(tài)的開創(chuàng)假設干節(jié)點。以下是用于鏈表處理的各個函數(shù):struct student * creat(struct student *p) /輸入函數(shù)void printall(struct student * head) /顯示所有記錄struct student * delet(struct student *head) /刪除函數(shù)struct student * insert(s

4、truct student *head) /插入函數(shù)struct student *searchbynum(struct student *head) /按學號查找struct student *searchbyname(struct student *head) /按姓名查找struct student *search(struct student *head) /查找函數(shù)menu_select() /選擇函數(shù)以下是各個函數(shù)的詳細說明:Creat函數(shù)用于創(chuàng)立鏈表,其中以n記錄節(jié)點的個數(shù),并在創(chuàng)立時實現(xiàn)自加,以便于后面函數(shù)的處理,其循環(huán)輸入的實現(xiàn),依靠庫函數(shù)malloc和后面的while循環(huán)。

5、Printall函數(shù)用于顯示當前的的所有記錄,依靠頭指針找到鏈表首地址,有while循環(huán)實現(xiàn)所有記錄的輸出。Delet函數(shù)用于刪除某個記錄,刪除可以按姓名或學號這兩種方式進展的,但本程序中沒有這個功能即只可以按學號進展刪除因為學號唯一。Insert函數(shù)用于插入,同樣以頭指針找到鏈表的首地址,并將要插入的學號依次與各個節(jié)點中得num比較,然后按順序將一個節(jié)點插入。Search函數(shù)用于查找,查找函數(shù)提供了兩種方式,即按姓名查找和按學號查找。在search函數(shù)中可以按提示調用searchbyname和searchbynum。Menu_select() 函數(shù)用于提供函數(shù)選項,旨在簡化主函數(shù)。流程圖22

6、1主函數(shù)Menu_select()PrintallSearchDeletInsertSearchbynameSearchbynumCreat12430此即為該程序的主流程圖。源程序以下是詳細的源程序及局部注釋:#include#include#include#include#include#define NULL 0#define LEN sizeof(struct student)#define SHU %dn%sn%5dn%ldn%sn%sn%sint n;struct studentlong num;char name20;int age;long telephone;char adre

7、ss40;char E_mail30;int QQ12;struct student *next;first;struct student * creat(struct student *p) /創(chuàng)立鏈表的函數(shù),即輸入函數(shù)struct student *head;struct student *p1,*p2;n=0; /先給n賦值0p1=p2=(struct student*) malloc(LEN);/強制類型轉換printf(ttt* 請輸入用戶信息 *n);printf(ttt輸入學號:n);scanf(%ld,&p1-num);printf(ttt輸入姓名:n);scanf(%s,&p

8、1-name);printf(ttt輸入年齡:n);scanf(%d,&p1-age);printf(ttt輸入 :n);scanf(%ld,&p1-telephone);printf(ttt輸入地址n);scanf(%s,&p1-adress);printf(ttt輸入E-mail:n);scanf(%s,&p1-E_mail);printf(ttt輸入QQn);scanf(%s,&p1-QQ);/40head=NULL;while(p1-num!=0)n=n+1; /實現(xiàn)n的自加,記錄節(jié)點的個數(shù)if(n=1)head=p1;elsep2-next=p1;p2=p1;p1=(struct s

9、tudent *) malloc(LEN);printf(ttt* 請輸入用戶信息 *n);printf(ttt輸入學號:n);scanf(%ld,p1-num);printf(ttt輸入姓名:n);scanf(%s,p1-name);printf(ttt輸入年齡:n);scanf(%d,p1-age);printf(ttt輸入 :n);scanf(%ld,p1-telephone);printf(ttt輸入地址n);scanf(%s,p1-adress);printf(ttt輸入E-mail:n);scanf(%s,p1-E_mail);printf(ttt輸入QQn);scanf(%s,p

10、1-QQ);p2-next=NULL;return 0;void printall(struct student * head) /顯示所有記錄struct student *p;printf(n全部的記錄如下n:);p=head;doprintf(SHU,p-num,p-name,p-age,p-telephone,p-adress,p-E_mail,p-QQ);p=p-next;while(p!=NULL);/80struct student * delet(struct student *head)/刪除函數(shù)long num;printf(請輸入要刪除的號碼:n);scanf(%ld,&

11、num);struct student *p1,*p2;if(head=NULL)printf(列表為空!n);return head;p1=head;while(num!=p1-num&p1-next!=NULL)p2=p1;p1-next;if(num=p1-num)if(p1=head)/要刪除的節(jié)點為首節(jié)點head=p1-next;elsep2-next=p1-next;printf(delet:%dn,num);n=n-1;/節(jié)點減一elseprintf(%d 未找到該節(jié)點!n,num);return head;struct student * insert(struct stude

12、nt *head)/插入函數(shù)struct student *stud;struct student *p0,*p1,*p2;p1=head;p0=stud;/p0指向的是要插入的節(jié)點if(head=0)head=p0;p0-next=NULL;/120elsewhile(p0-nump1-num)&(p1-next!=NULL)p2=p1;p1=p1-next;if(p0-numnum)if(head=p1)head=p0;/插入到原來第一個節(jié)點之前elsep2-next=p0;p0-next=p1;/插入到p2所指的節(jié)點之后n=n+1;return head;struct student *

13、searchbynum(struct student *head)/按學號查找long numb;printf(請輸入要刪除的號碼:n);scanf(%ld,&numb);struct student *p;p=head;/147scanf(%ld,&numb);if(numb!=p-num)p=p-next;elseprintf(SHU,p-num,p-name,p-age,p-telephone,p-adress,p-E_mail,p-QQ);return head;struct student *searchbyname(struct student *head)/按姓名查找char a

14、100;printf(請輸入要查找的姓名:n);scanf(%s,a);struct student *p;p=head;scanf(%s,a);if(strcmp(a,p-name)!=0)p=p-next;elseprintf(SHU,p-num,p-name,p-age,p-telephone,p-adress,p-E_mail,p-QQ);return head;struct student *search(struct student *head)char choic;printf(ttt1-按 號碼查找 2-按姓名查找);printf(ttt請選擇:);choic=getch();

15、switch (choic) case 1:searchbynum(&first);break; case 2:searchbyname(&first);break; return head;int menu_select() char s80; int a;/定義整形變量 system(cls); printf(tt*歡迎進入通訊管理界面*nn); printf(ttt0. 輸入記錄n); printf(ttt1. 顯示記錄n); printf(ttt2. 查找n); printf(ttt3. 插入記錄 n); printf(ttt4. 刪除記錄n); printf(ttt5. Quitn)

16、; printf(tt*nn);doprintf(Enter you choice(05):); scanf(%s,s); a=atoi(s); while (a5); return a; main()printf(tt*n); printf(tt*welcome to TONGXUNLU *n); printf(tt#code by 陳國警 #n); printf(tt*n); printf(按任意鍵進入主菜單n); getch(); int selectnum; /選擇函數(shù),提示選擇各種鏈表處理函數(shù)。 while(1) selectnum = menu_select(); switch(s

17、electnum) case 0:creat(&first);break;case 1: printall(&first); break;case 2: search(&first); break;case 3: insert(&first); break;case 4: delet(&first); break;case 5:printf(BYE BYE!n);system(pause); /系統(tǒng)暫停getchar(); exit(0); getchar(); return 0;以下是局部運行結果:初始化的界面選擇界面:創(chuàng)立鏈表中的輸入界面:查找中的提示界面:限于篇幅,運行結果就只列舉這么多。上機總結這是自從學習C語言以來我編寫過的最大的一個程序,編寫的時候遇到了前所未有的困難。因為這個程序所涉及到的知識,全部是要靠自學掌

溫馨提示

  • 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

提交評論