版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、C語言課程設計報告 題 目:設計一個簡單的計算器設 計 者: 陳玉文專業(yè)班級:通信工程0803學 號:指導教師: 年 月 日河南理工大學計算機學院目錄一、 設計任務書二、 本組課題及本人任務三、 程序功能簡介四、 主要內(nèi)容1、 設計分析2、 程序結(jié)構3、 各模塊功能及程序說明4、 源程序5、 操作方法6、 實驗結(jié)果7、 設計體會5、 附錄6、 參考文獻一、設計任務書該程序編譯的是通訊錄,可以實現(xiàn)一般主要功能有:有建立通訊錄的個人信息功能,如記錄該人姓名信息,地址信息,出生日期信息,所在城市信息,以及其城市的郵編信息等,刪除個人信息,通訊錄個人的信息列表,個人的信息查詢,個人的信息保存,以及個人
2、的信息提取的功能,最后可以直接退出通訊錄。當然實行不同的功能需要定義不同的功能函數(shù),在記錄個人信息定義不同的結(jié)構體,每一個成員的信息可以是一個基本類型或者是一個夠造類型,對結(jié)構體變量的應用,其中包括賦值,輸入,輸出,運算等方式來實現(xiàn)結(jié)構變量的成員。當然也可以執(zhí)行該程序應用了函數(shù)的調(diào)用,自定義函數(shù)以及文件的存儲與調(diào)用等。個人的信息保存在這個問題上,這信息可以動態(tài)的分配到內(nèi)存空間,每一次分配一塊空間用來存放一個人的個人信息的數(shù)據(jù),定義兩個域,一個是數(shù)據(jù)域,用來存放各種實際的數(shù)據(jù),如個人姓名信息,個人地址信息,出生日期等等數(shù)據(jù)。在編輯程序,用到了基本的循環(huán)、選擇、排序的算法,使用數(shù)組或數(shù)組元素的指針
3、和指針變量,對結(jié)構體及其元素用指針或指針變量來指向。并且使用多種預處理功能,如宏定義、文件包含、條件編譯等。來進行程序的修改、閱讀、移植和調(diào)試,也有利于實現(xiàn)模塊化程序設計。程序員在程序中用預處理命令來調(diào)用這些功能。通訊錄的個人信息數(shù)據(jù)的編輯、存儲、列表、刪除、查詢、提取等實行運用,在程序中存儲二百人的個人信息空間,日期不能超過兩個字符。在運行后,程序自動給出提示選擇,給出你所需要執(zhí)行的功能,在選擇后會給出相應的顯示和下一步的提示,在編輯個人信息時必須有姓名,否者會返回上一選擇菜單,有部分信息可以不填。在編輯完后,就可以實行其他功能,將給出其他選擇,如將個人信息刪除、將個人信息列表、保存?zhèn)€人信息
4、、提取個人信息等等的功能。最后在執(zhí)行完后就可直接根據(jù)提示選擇退出。就實現(xiàn)了整個通訊錄的流程。2、 本組課題及本人任務本組總共兩個人,一個是我,令一個是通信三班的劉瑩()。該組設計的是一個通訊錄,我主要完成的任務是建立通訊錄的個人信息,如姓名,地址,出生日期,城市,郵編等;查找個人信息。三、程序功能簡介該程序主要功能有:有建立通訊錄的個人信息,如姓名,地址,出生日期,城市,郵編等。也可以執(zhí)行刪除個人信息,通訊錄信息列表,信息查詢,信息保存,以及信息提取的功能,最后可以退出通訊錄。該程序應用了函數(shù)的調(diào)用,自定義函數(shù)以及文件的存儲與調(diào)用等,使用數(shù)組或數(shù)組元素的指針和指針變量,對結(jié)構體及其元素用指針或
5、指針變量來指向。4、 主體內(nèi)容 1、設計分析以無歧義的陳述說明程序設計的任務,強調(diào)的是程序要做什么1)輸入的形式和輸入值得范圍;2)輸出的形式;3)程序所能達到的功能; 4)測試數(shù)據(jù):包括正確的輸入結(jié)果和含有錯誤的輸入及其輸出結(jié)果; 2、程序結(jié)構開 始輸 入輸入結(jié)構體各元素輸出結(jié)構體中各元素結(jié) 束3、 各模塊的功能及程序說明1、輸入保存結(jié)構 該結(jié)構實現(xiàn)的功能主要是從鍵盤輸入個人的信息,如電話號碼,地址,出生日期,城市,郵編等,然后保存,以方便以后的查詢。程序說明:(1)輸入個人信息:名字,地址,日期,郵政編碼void enter(void)struct address *info;for(;)
6、info=(struct address *)malloc(sizeof(struct address);if(!info)printf("nout of memory");return;inputs("please enter name:",info->name,30);if(!info->name0) break;/*stop entering*/inputs("please enter street:",info->street,40);inputs("please enter city:"
7、,info->city,20);inputs("please enter state:",info->state,3);inputs("please enter zip:",info->zip,10);dls_store(info,&start,&last);/*entry loop*/如果超過給定內(nèi)存,將給出提示,輸入太長:void inputs(char *prompt,char *s,int count)char p225;do printf(prompt);fgets(p,254,stdin);if(strlen
8、(p)>count)printf("nToo Longn"); while(strlen(p)>count);pstrlen(p)-1=0;/* remove newline character */strcpy(s,p);(2)制作列表,對輸入的個人信息進行存儲與排列void dls_store(struct address *i,/*new element*/struct address *start,/*first element in list*/struct address *last/*last element in list*/)struct ad
9、dress *old,*p;if(*last=NULL)/*first element in list*/i->next=NULL;i->prior=NULL;*last=i;*start=i;return;p=*start;/*start at top of list*/old=NULL;while(p)if(strcmp(p->name,i->name)<0)old=p;p=p->next;elseif(p->prior)p->prior->next=i;i->next=p;i->prior=p->prior;p-&g
10、t;prior=i;return;i->next=p;/*new first element*/i->prior=NULL;p->prior=i;*start=i;return;old->next=i;/*put on end*/i->next=NULL;i->prior=old;*last=i;2、 查詢功能模塊 該結(jié)構主要實現(xiàn)的功能是從鍵盤輸入人的信息,如地址,出生日期等,然后查找出他的通信方式。 程序說明:(2)從其內(nèi)存中查找某個名字,并進行輸出,如果沒有就輸出沒有發(fā)現(xiàn)名字struct address *find(char *name)struct a
11、ddress *info;info=start;while(info)if(!strcmp(name,info->name ) return info;info = info->next; /* get next address */printf("Name not found.n");return NULL; /*not found*/(3)將通訊錄中所有個人信息分別列出void list(void)struct address *info;info=start;while(info)display(info);info = info->next; /*
12、 get next address */printf("nn");(4)分別輸出個人信息void display(struct address *info)printf("%sn",info->name);printf("%sn",info->street);printf("%sn",info->city);printf("%sn",info->state);printf("%sn",info->zip);printf("nn"
13、;);(5)根據(jù)其個人信息的存儲地址來查找個人名字信息void search(void)char name40;struct address *info;printf("Enter name to find:");gets(name);info = find(name);if(!info) printf("Not Foundn");else display(info);3、修改、刪除結(jié)構 該結(jié)構主要是在查找的基礎之上,把原來的信息進行修改或刪除操作。4、保存、提取結(jié)構該結(jié)構能動態(tài)的分配內(nèi)存空間,每一次分配一塊空間用來存放一個人的個人信息的數(shù)據(jù),定義兩個域
14、,一個是數(shù)據(jù)域,用來存放各種實際的數(shù)據(jù),如個人姓名信息,個人地址信息,出生日期等等,必要的時候還能提取出個人的信息。4、源程序 #include"stdio.h" #include"stdlib.h" #include"string.h" struct addresschar name30;char street40;char city20;char state3;char zip11;struct address *next;struct address *prior;struct address *start;struct add
15、ress *last;struct address *find(char *);void enter(void),search(void),save(void);void load(void),list(void);void mldelete(struct address *,struct address *);void dls_store(struct address *i,struct address *start,struct address *last);void inputs(char *,char*,int),display(struct address *);int menu_s
16、elect(void);int main(void)start=last=NULL;for(;)switch(menu_select()case 1:enter();break;case 2:mldelete(&start,&last);break;case 3:list();break;case 4:search();break;case 5:save();break;case 6:load();break;case 7:exit(0);return 0;int menu_select(void)char s80;int c;printf("*tongxunlu*n
17、");printf("*1.Enter a name *n");printf("*2.delete a name *n");printf("*3.list the file *n");printf("*4.search *n"); printf("*5.save the file *n");printf("*6.load the file *n");printf("*7.Quit *n"); printf("*n");do p
18、rintf("nplease enter your choice:");gets(s);c=atoi(s);while(c<0|c>7);return c; /*Enter names and address.*/void enter(void)struct address *info;for(;)info=(struct address *)malloc(sizeof(struct address);if(!info)printf("nout of memory");return;inputs("please enter name
19、:",info->name,30);if(!info->name0) break;/*stop entering*/inputs("please enter street:",info->street,40);inputs("please enter city:",info->city,20);inputs("please enter state:",info->state,3);inputs("please enter zip:",info->zip,10);dls_
20、store(info,&start,&last);/*entry loop*/*/void inputs(char *prompt,char *s,int count)char p225;do printf(prompt);fgets(p,254,stdin);if(strlen(p)>count)printf("nToo Longn"); while(strlen(p)>count);pstrlen(p)-1=0;/* remove newline character */strcpy(s,p);/*Create a doubly linked
21、 list in sorted order */void dls_store(struct address *i,/*new element*/struct address *start,/*first element in list*/struct address *last/*last element in list*/)struct address *old,*p;if(*last=NULL)/*first element in list*/i->next=NULL;i->prior=NULL;*last=i;*start=i;return;p=*start;/*start
22、at top of list*/old=NULL;while(p)if(strcmp(p->name,i->name)<0)old=p;p=p->next;elseif(p->prior)p->prior->next=i;i->next=p;i->prior=p->prior;p->prior=i;return;i->next=p;/*new first element*/i->prior=NULL;p->prior=i;*start=i;return;old->next=i;/*put on end*/
23、i->next=NULL;i->prior=old;*last=i;/*Remove an element from the list*/void mldelete(struct address *start,struct address *last)struct address *info;char s80;inputs("Enter name:",s,30);info=find(s);if(info)if(*start=info)*start=info->next;if(*start)(*start)->prior=NULL;else *last
24、=NULL;elseinfo->prior->next=info->next;if(info!=*last)info->next->prior=info->prior;else*last=info->prior;free(info); /*return memory to system*/*Find an address.*/struct address *find(char *name)struct address *info;info=start;while(info)if(!strcmp(name,info->name ) return i
25、nfo;info = info->next; /* get next address */printf("Name not found.n");return NULL; /*not found*/* Display the entire list */void list(void)struct address *info;info=start;while(info)display(info);info = info->next; /* get next address */printf("nn");/* this function actua
26、lly prints the fields in each address.*/void display(struct address *info)printf("%sn",info->name);printf("%sn",info->street);printf("%sn",info->city);printf("%sn",info->state);printf("%sn",info->zip);printf("nn");/* Look for
27、 a name in the list */void search(void)char name40;struct address *info;printf("Enter name to find:");gets(name);info = find(name);if(!info) printf("Not Foundn");else display(info);/* Save the file to disk */void save(void)struct address *info;FILE *fp;fp = fopen("mlist"
28、;,"wb");if(!fp)printf("Cannot open file.n");exit(1);printf("nSaving Filen");info = start;while(info)fwrite(info,sizeof(struct address),1,fp);info = info->next ; /* get next address */fclose(fp);/* Load the address file. */void load()struct address *info;FILE *fp;fp=f
29、open("mlist","rb");if(!fp)printf("Cannot open file.n");exit(1);/* free any previously allocated memory */while(start)info=start->next;free(info);start=info;/* reset top and bottom pointers */start=last=NULL;printf("nLoading Filen");while(!feof(fp)info=(struct address *) malloc(sizeof(struct address);if(!in
溫馨提示
- 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年山西電力職業(yè)技術學院高職單招職業(yè)適應性測試近5年常考版參考題庫含答案解析
- 2025年山東輕工職業(yè)學院高職單招職業(yè)技能測試近5年??及鎱⒖碱}庫含答案解析
- 沼渣與雜鹵石共熱解制備新型肥料技術研究
- 考慮土-結(jié)構相互作用的框架結(jié)構抗震分析與參數(shù)識別
- 2025年安徽水利水電職業(yè)技術學院高職單招語文2018-2024歷年參考題庫頻考點含答案解析
- 2025年安徽工業(yè)職業(yè)技術學院高職單招語文2018-2024歷年參考題庫頻考點含答案解析
- 2025年寧波城市職業(yè)技術學院高職單招語文2018-2024歷年參考題庫頻考點含答案解析
- 地板恢復施工方案書
- 路面透層施工方案
- 2025年大連職業(yè)技術學院高職單招高職單招英語2016-2024歷年頻考點試題含答案解析
- 中國成人暴發(fā)性心肌炎診斷和治療指南(2023版)解讀
- 新生兒低血糖課件
- 自動上下料機械手的設計研究
- 電化學儲能電站安全規(guī)程
- 幼兒園學習使用人民幣教案教案
- 2023年浙江省紹興市中考科學真題(解析版)
- 語言學概論全套教學課件
- 大數(shù)據(jù)與人工智能概論
- 《史記》上冊注音版
- 2018年湖北省武漢市中考數(shù)學試卷含解析
- 《腎臟的結(jié)構和功能》課件
評論
0/150
提交評論