版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
中國(guó)地質(zhì)大
學(xué)本科生課程論文封面課程
名
稱
C
語(yǔ)言程序設(shè)計(jì) 教師
姓
名
本科生姓名
本科生學(xué)號(hào)
本科生專業(yè)
所在
院
系
類別:
日期:
12課程設(shè)計(jì)評(píng)語(yǔ)對(duì)課程論文的評(píng)語(yǔ):平時(shí)成績(jī):課程論文成績(jī):總
成績(jī):評(píng)閱人簽名:注:1、無(wú)評(píng)閱人簽名成績(jī)無(wú)效;2、必須用鋼筆或圓珠筆批閱,用鉛筆閱卷無(wú)效;3、如有平時(shí)成績(jī),必須在上面評(píng)分表中標(biāo)出,并計(jì)算入總成績(jī)。3目
錄課程設(shè)計(jì)評(píng)語(yǔ)........................................................................................................................................2目
錄......................................................................................................................................................31.課程論文題目..................................................................................................................................42.程序設(shè)計(jì)思路..................................................................................................................................43.功能模塊圖......................................................................................................................................54.?dāng)?shù)據(jù)結(jié)構(gòu)設(shè)計(jì)..................................................................................................................................55.算法設(shè)計(jì)..........................................................................................................................................56.程序代碼........................................................................................................................................147.程序運(yùn)行結(jié)果................................................................................................................................148.編程中遇到的困難及解決方法...................................................................................................
279.總結(jié)心得及良好建議....................................................................................................................2810.致謝..............................................................................................................................................2841.課程論文題目通訊錄管理系統(tǒng)要求:設(shè)計(jì)具有數(shù)據(jù)插入、修改、刪除、顯示和查詢功能的電話簿管理系統(tǒng)。⑴數(shù)據(jù)包括:人名、工作單位、電話號(hào)碼和
地址。⑵可對(duì)記錄中的姓名和電話號(hào)碼進(jìn)行修改。⑶可增加或刪除記錄。⑷可顯示所有保存的記錄。⑸可按人名或電話號(hào)碼進(jìn)行查詢。2.程序設(shè)計(jì)思路根據(jù)題目的要求,程序應(yīng)該采用結(jié)構(gòu)體數(shù)組和文件系統(tǒng)實(shí)現(xiàn)。應(yīng)該有動(dòng)態(tài)的存儲(chǔ)空間和文件輸入、輸出等操作功能;在程序中應(yīng)該包括添加、顯示、刪除、查詢和修改以及保存和退出的功能;另外還應(yīng)提供鍵盤(pán)式選擇菜單實(shí)現(xiàn)功能選擇。3.功能模塊圖4.?dāng)?shù)據(jù)結(jié)構(gòu)設(shè)計(jì)5整個(gè)程序中用到的數(shù)據(jù)主要是全局變量
MAX
100
和字符變量
name[10]、addr[20]、phnum[20]、email[20]。5.算法設(shè)計(jì)1.
主函數(shù)主函數(shù)的設(shè)計(jì)一般比較的簡(jiǎn)單,只提供輸入,功能處理和輸出部分的函數(shù)調(diào)用。其中個(gè)功能模塊用菜單方式選擇。菜單部分也可以寫(xiě)成函數(shù)。[流程圖]/*****************主函數(shù)*****************//**********變量保存選擇菜單數(shù)子***************/6[程序]main(){intn;creat();do{printf("\n\t***********************************************\n");printf("\n\n\t*************WELCOMETOUSE!***************\n");printf("\n\t**********************************************\n");printf("\n\n\t\t*****Pleasemakeachoicebelow*****\n");printf("\n\t\t1.Addapieceof
meg");printf("\n\t\t2.Listallthemeg");printf("\n\t\t3.Deleteapieceofmeg");printf("\n\t\t4.Findapieceofmeg");printf("\n\t\t5.Alterapieceofmeg");printf("\n\t\t6.SaveandQuit");printf("\n\t\t7.Createanaddressbook");printf("\n\n\n");printf("\t********InputYourChoice:****************\n");scanf("%d",&n);switchswitch(n) /*****************輸入n的在1-6之間執(zhí)
行************/{case
1: Add(); /*添加模塊*/break;case
2:/*顯示模塊*/case
3:List();break;Delete();/*刪除模塊*//*查詢模塊:分為名字查詢(0)和電話號(hào)碼查詢(1)*/break;case
4: Find();break;case
5: Alter();/*修改模塊:分為修改名字(0)和修改電話號(hào)碼(1)*//*退出模塊*/break;case
6: exit(0);break;case
7: creat();/*帶回鏈表起始地址*/default:fclose(fp);/**********輸入的
n
不在
1-6
之間執(zhí)行
default
************/printf("\n\t********************************************\n");printf("\n\t The
numshould
be
1-6!!! \n");printf("\n\t********************************************\n");break;}}while(1);}2.各功能模塊設(shè)計(jì)[數(shù)據(jù)結(jié)構(gòu)]通訊錄的數(shù)據(jù)信息:人名、工作單位、電話號(hào)碼、E-mail
地址均可以采用字符型數(shù)組;可以采用結(jié)構(gòu)體的形式,把各信息作為結(jié)構(gòu)的成員,由于通訊錄要具78有添加、查找、和刪除的功能,所以整個(gè)通訊錄采用鏈表比較容易的實(shí)現(xiàn)以上功能。用結(jié)構(gòu)體變量作為鏈表中的接點(diǎn)是最合適的。結(jié)構(gòu)體變量可以是指針類型,我們可以用這個(gè)指針類型的成員來(lái)存放下一個(gè)結(jié)點(diǎn)的地址。結(jié)構(gòu)體的類型如下:struct
persons{ typedefstructp{name[10];addr[20];phnum[20];email[20];char
name[10] charchar
addr[20]; charchar
phnum[20]; charchar
email[20]; char}persons[MAX]; struct
p*next;}p,*linklist;structpersons
類型為每個(gè)鏈表成員;
typedef
structp為一個(gè)動(dòng)態(tài)的結(jié)點(diǎn),它的成員next
存放下一個(gè)結(jié)點(diǎn)的地址。以下為各模塊分析時(shí)要用的指針:/**************
定義頭指針和尾指針/********************定義文件指
針linklist
head=NULL,t=NULL;*************/p *s,*p0,*p1,*p2,*p3,*p4,*p5;int
i;char
name1[10],ch;charstr1[20];FILE
*fp;***********************/(1)輸入模塊[程序]/*將文件的信息讀入結(jié)構(gòu)體數(shù)組在轉(zhuǎn)存入鏈表中*/void
creat(){intj;long
k;打開(kāi)文件fp=fopen("people.txt","r+");/**************************************/if(fp!=NULL){for(i=1;i<MAX;i++){j=fgetc(fp);if(j==EOF)return;k=i-1;9fseek(fp,k*sizeof(struct
persons),0); /************
讀
取
一
個(gè)
人
的
信
息***************/fread(&persons[i],sizeof(struct
persons),1,fp);/**************裝存入鏈表中***********//***********
用尾插法將其插入鏈表中s=(linklist)malloc(sizeof(p));strcpy(s->name,persons[i].name);strcpy(s->addr,persons[i].addr);strcpy(s->phnum,persons[i].phnum);strcpy(s->email,persons[i].email);if(head==NULL)**********/head=s;else{t->next=s;t=s;}}}else{fp=fopen("people.txt","w"); i=1; /*****不能打開(kāi)另開(kāi)辟一個(gè)文件*****/}}⑵添加模塊由于運(yùn)用的是鏈表的形式,且通訊錄只是按照輸入的先后循序排序,所以對(duì)添加的信息采用插入末端的方式,同時(shí)添加也使用于空通訊錄的信息輸入。[程序]void
Add() /*******向通訊錄中添加(或輸入)一個(gè)人的信息*********/{s=(linklist)malloc(sizeof(p));s->next=NULL;printf("\n\n\t*********Pleaseinputthesb'smessage:**********");printf("\n\n\t\tname:");scanf("%s",s->name);printf("\n\n\t\tAddr:");scanf("%s",s->addr);printf("\n\n\t\tphnum:");scanf("%s",s->phnum);printf("\n\n\t\temai:");scanf("%s",s->email);if(head==NULL)/*******
若通訊錄為空則添加在頭指針之后相當(dāng)于輸入信息/***********添加到鏈表的末尾************/head=s;*********/else{t->next=s;t=s;
}}⑶顯示模塊鏈表的一大好處是只要定義了頭指針,則所有的信息就很容易的找到,指針會(huì)一環(huán)扣一環(huán)的找到每個(gè)信息,顯示出每個(gè)信息,直到最后到位指針結(jié)束。[程序]void
List(){p0=head;/*****************顯示所有的信息*******************//**************
p0
指向頭指針*******************//****************通訊錄不為
空while(p0!=NULL)******************/{printf("\tname:%s",p0->name);printf("\taddr:%s",p0->addr);printf("\tphnum:%s",p0->phnum);printf("\temail:%s\n",p0->email);p0=p0->next; /**************
p0
向后移一個(gè)位置*****************/}}⑷刪除模塊刪除一個(gè)人的信息相當(dāng)于是刪除鏈表中的一個(gè)結(jié)點(diǎn)。在刪除后又要保證鏈表不間斷,如同手牽手排隊(duì)的小孩,一個(gè)離隊(duì)后,它兩側(cè)的小孩又自動(dòng)地把手牽起來(lái),保證不間斷即把結(jié)點(diǎn)從鏈表中分離開(kāi)來(lái),只要撤銷原來(lái)的鏈表關(guān)系即可。[流程圖]要?jiǎng)h除地信息/************定義一個(gè)刪除的函數(shù)***************/[程序]void
Delete(){char
name0[10];p1=head;/*輸入要?jiǎng)h除人printf("\n\t**********Pleaseinputa
name:*************\n");的姓名*/printf("\n\t\tname0:");gets(name0);scanf("%s",name0);/*根據(jù)各種情況判斷while((strcmp(name0,p1->name)!=0)&&(p1!=NULL))可能性*/{p2=p1;p1=p1->next;} /***************
指
針
向
后
移
一
個(gè)
位
置****************//******找到要?jiǎng)h除的位置*******/if(strcmp(name0,p1->name)==0){if(p1==head)head=p1->next;elsep2->next=p1->next;printf("\n\t**************Delete
success!******************\n");}p2=p1p1=p1->next p1->nexxt10/***********定義一個(gè)查詢的函數(shù)**************/[程序]void
Find(){int
n;charphnum1[20],name1[10];printf("\n\t*******Searchbynameorphpnum?*****name(n=0)\phnum(n=1)*********\n");printf("*******Inputthenumberof
'n':*************\n");scanf("%d",&n);if(n==0)/*******************選擇查詢方式******************//****************姓名查詢***************/{printf("\n\tname:");p3=head;gets(name1);scanf("%s",&name1);/*****************輸入姓名***************/while((strcmp(name1,p3->name)!=0)&&(p3!=NULL))
/*根據(jù)各種情況判斷可能性*/p3=p3->next;if(p3->name==NULL) /**************沒(méi)有找到**************/{printf("\n\t**************Cannotfindthe
message!**********");}else
if(strcmp(name1,p3->name)==0) /******找到信息并輸出******/elseprintf("\n\t**************Delete
fail!******************\n");
/*
沒(méi)找到要?jiǎng)h除的位置*/}⑸查詢模塊按照題目的要求查詢可以分為姓名查詢和電話號(hào)碼查詢[流程圖]查詢選擇查詢方式輸入姓名:輸入電話號(hào)碼:找到
找到
找到的提示信息找到的提示信息未找到提示信息未找到提示信息11{printf("\n\t*********Foundthemessage:**********\n");printf("\n\tname:
%s",p3->name);printf("\taddress:%s",p3->addr);printf("\temail:%s",p3->email);printf("\tphnum:
%s",p3->phnum);/***************電話號(hào)碼查詢***************/}}else
if(n==1){printf("\n\tphnum1");p3=head;gets(phnum1);scanf("%s",&phnum1);/****************輸入電話號(hào)碼***************/while((strcmp(phnum1,p3->phnum)!=0)&&(p3!=NULL))
/*根據(jù)各種情況判斷可能性*/p3=p3->next;if(p3->phnum==NULL) /***************沒(méi)有找到**************/{printf("\n\t************Cannot
find
the message!***********");}else
if(strcmp(phnum1,p3->phnum)==0) /******找到信息并輸出******/{printf("\n\n\t**********Foundthemessage:*********");printf("\n\tname:
%s",p3->name);⑹修改模塊按照題目的要求查詢可以分為修改姓名和修改電話號(hào)碼,修改模塊的設(shè)計(jì)思路和查詢模塊的思路基本上相同。[流程圖]修改修改內(nèi)容
輸入姓名:輸入電話號(hào)碼:
未找到找到信息找到信息未找到信息修改失敗輸入新的姓名提示修改成功輸入新的電話號(hào)碼提示修改成功修改失敗1213[程序]void
Alter()/***************定義一個(gè)修改的函數(shù)*****************/{intm;char
phnum2[20],name2[10];printf("\n\n\t****Which
message do
you
wanttoalter?*******name(m=0)\phnum(m=1)*********\n");printf("************Inputthenumberof
'm':******************\n");/*******************選擇修改內(nèi)容******************//*********************修改姓名*********************//**************輸入要修改的姓名***************/scanf("%d",&m);if(m==0){printf("\n\tname:");scanf("%s",&name2);p4=head;while((strcmp(name2,p4->name)!=0)&&(p4!=NULL))
/*根據(jù)各種情況判斷可能性*/p4=p4->next;if(p4==NULL){printf("\n\t*********Cannotfindthe
mame!**********\n");}else
if(strcmp(name2,p4->name)==0) /********找到要修改的姓名********/{printf("\n\n\t*********Inputthenewnessage:************\n");printf("\n\n\n\t\tname:");canf("%s",&name2);strcpy(p4->name,name2);/**********輸入新的信息**********//*******新的姓名修改成功*******/printf("\n\n\t************Altered
success!************\n");}/***************修改電話號(hào)碼***************/}else
if(m==1){printf("\n\tphnum:");scanf("%s",&phnum2); /************輸入要修改的電話號(hào)碼***************/p4=head;/*根據(jù)各種情況判斷可能性*/while((strcmp(phnum2,p4->phnum)!=0)&&(p4!=NULL))p4=p4->next;if(p4==NULL){printf("\n\t************Cannotfindthe
phnum!*********\n");}else
if(strcmp(phnum2,p4->phnum)==0) /******找到要修改的電話號(hào)碼*****/{printf("\n\n\t**********Inputthenewnessage:*********\n");printf("\n\n\n\t\tphnum:");scanf("%s",&phnum2);strcpy(p4->phnum,phnum2);/**********輸入新的信息**********//*******新的電話號(hào)碼修改成功*******/printf("\n\n\t************Altered
success!************\n");}}}⑺保存模塊14/************定義一個(gè)保存信息的函數(shù)************/[程序]void
Save(){int
j;fp=fopen("people.txt","w");for(p5=head,j=0;p5!=NULL;j++,p5=p5->next) /*將信息裝出入結(jié)構(gòu)體數(shù)組在出入鏈表中*/{strcpy(persons[j].name,p5->name);strcpy(persons[j].addr,p5->addr);strcpy(persons[j].phnum,p5->phnum);strcpy(persons[j].email,p5->email);fwrite(&persons[j],sizeof(struct
persons),1,fp);}}6.程序代碼#include<stdio.h>#include<stdlib.h>#include
<string.h>#defineMAX100struct
persons{char
name[10];charaddr[20];charphnum[20];charemail[20];}persons[MAX];typedefstruct
p{charname[10];charaddr[20];char
phnum[20];charemail[20];structp
*next;}p,*linklist;linklist
head=NULL,t=NULL;p *s,*p0,*p1,*p2,*p3,*p4,*p5;int
i;char
name1[10],ch;scanf("%s",s->addr);15charstr1[20
];FILE
*fp;void
creat(){ int
j;long
k;fp=fopen("people.txt","r+");if(fp!=NULL){for(i=1;i<MAX;i++){
j=fgetc(fp);if(j==EOF)return;k=i-1;fseek(fp,k*sizeof(structpersons),0);fread(&persons[i],sizeof(structpersons),1,fp);s=(linklist)malloc(sizeof(p));strcpy(s->name,persons[i].name);strcpy(s->addr,persons[i].addr);strcpy(s->phnum,persons[i].phnum);strcpy(s->email,persons[i].email);if(head==NULL)head=s;else{t->next=s;t=s;}}}else{
fp=fopen("people.txt","w"); i=1;}}void
Add(){ s=(linklist)malloc(sizeof(p));s->next=NULL;printf("\n\n\t*********Pleaseinputthesb'smessage:**********");printf("\n\n\t\tname:");scanf("%s",s->name);printf("\n\n\t\tAddr:");elseprintf("\n\t**************Delete
fail!******************\n");16printf("\n\n\t\tphnum:");scanf("%s",s->phnum);printf("\n\n\t\temai:");scanf("%s",s->email);if(head==NULL)head=s;else{t->next=s;t=s;}}void
List(){p0=head;while(p0!=NULL){printf("\tname:%s",p0->name);printf("\taddr:%s",p0->addr);printf("\tphnum:%s",p0->phnum);printf("\temail:%s\n",p0->email);p0=p0->next;}}void
Delete(){char
name0[10];p1=head;printf("\n\t**********Pleaseinputaname:**************\n");printf("\n\t\tname0:");gets(name0);scanf("%s",name0);while((strcmp(name0,p1->name)!=0)&&(p1!=NULL)){p2=p1;p1=p1->next;}if(strcmp(name0,p1->name)==0){if(p1==head)head=p1->next;elsep2->next=p1->next;printf("\n\t**************Delete
success!******************\n");}p3=p3->next;17}void
Find(){int
n;charphnum1[20],name1[10];printf("\n\t*******Searchbynameorphpnum?*****name(n=0)\phnum(n=1)*********\n");printf("*******Inputthenumberof
'n':*************\n");scanf("%d",&n);if(n==0){printf("\n\tname:");p3=head;gets(name1);scanf("%s",&name1);while((strcmp(name1,p3->name)!=0)&&(p3!=NULL))p3=p3->next;if(p3->name==NULL){printf("\n\t**************Cannotfindthe
message!**********");}elseif(strcmp(name1,p3->name)==0){printf("\n\t*******Foundthemessage:**********************\n");printf("\n\tname:
%s",p3->name);printf("\taddress:%s",p3->addr);printf("\temail:%s",p3->email);printf("\tphnum:
%s",p3->phnum);}}else
if(n==1){
printf("\n\tphnum1");p3=head;gets(phnum1);scanf("%s",&phnum1);while((strcmp(phnum1,p3->phnum)!=0)&&(p3!=NULL))18message!*********");}if(p3->phnum==NULL){printf("\n\t************Cannotfindtheelse
if(strcmp(phnum1,p3->phnum)==0){ printf("\n\n\t**********Foundthemessage:*********");printf("\n\tname:
%s",p3->name);printf("\taddress:%s",p3->addr);printf("\temail:%s",p3->email);printf("\tphnum:
%s",p3->phnum);}}}void
Alter(){intm;char
phnum2[20],name2[10];toprintf("\n\n\t****Which message do you wantalter?****name(m=0)\phnum(m=1)*********\n");printf("************Inputthenumberof'm':***********************\n");scanf("%d",&m);if(m==0){printf("\n\tname:");scanf("%s",&name2);p4=head;while((strcmp(name2,p4->name)!=0)&&(p4!=NULL))p4=p4->next;if(p4==NULL){printf("\n\t*********Cannotfindthemame!**********\n");}elseif(strcmp(name2,p4->name)==0){ printf("\n\n\t*********Inputthenewnessage:************\n");printf("\n\n\n\t\tname:");scanf("%s",&name2);strcpy(p4->name,name2);printf("\n\n\t************Altered
success!************\n");}}else
if(m==1){
printf("\n\tphnum:");scanf("%s",&phnum2);p4=head;while((strcmp(phnum2,p4->phnum)!=0)&&(p4!=NULL))p4=p4->next;if(p4==NULL)19{printf("\n\t************Cannotfindthephnum!*********\n");}elseif(strcmp(phnum2,p4->phnum)==0){ printf("\n\n\t**********Inputthenewnessage:*********\n");printf("\n\n\n\t\tphnum:");scanf("%s",&phnum2);strcpy(p4->phnum,phnum2);printf("\n\n\t************Altered
success!************\n");}}}void
Save(){intj;fp=fopen("people.txt","w");for(p5=head,j=0;p5!=NULL;j++,p5=p5->next){ strcpy(persons[j].name,p5->name);strcpy(persons[j].addr,p5->addr);strcpy(persons[j].phnum,p5->phnum);strcpy(persons[j].email,p5->email);fwrite(&persons[j],sizeof(struct
persons),1,fp);}}main(){int
n;creat();do{printf("\n\t***********************************************\n");printf("\n\n\t*************WELCOMETOUSE!***************\n");printf("\n\t**********************************************\n");printf("\n\n\t\t*****Ple
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 急救設(shè)備操作與維護(hù)護(hù)理
- 中職護(hù)理護(hù)理技術(shù)操作規(guī)范
- 人工智能助力護(hù)理質(zhì)量提升
- 崇義中學(xué)高二下學(xué)期第二次月考物理試題
- 2025年并購(gòu)重組承銷補(bǔ)充協(xié)議
- 2025年搬家服務(wù)合同協(xié)議
- 2025年AI煤礦安全監(jiān)測(cè)系統(tǒng)中傳感器漂移實(shí)時(shí)校正
- 破陣子·為陳同甫賦壯詞以寄之 課件 2025-2026學(xué)年語(yǔ)文九年級(jí)下冊(cè)統(tǒng)編版
- 疫情防控宣傳試題及答案
- 2026 年中職酒店管理(酒店基礎(chǔ))試題及答案
- 紡織業(yè)賬務(wù)知識(shí)培訓(xùn)課件
- 1688采購(gòu)合同范本
- 購(gòu)買(mǎi)鐵精粉居間合同范本
- GB/T 29730-2025冷熱水用分集水器
- 污水廠安全知識(shí)培訓(xùn)
- (2025年標(biāo)準(zhǔn))存單轉(zhuǎn)讓協(xié)議書(shū)
- 醫(yī)學(xué)科研誠(chéng)信專項(xiàng)培訓(xùn)
- 電力通信培訓(xùn)課件
- 第五版FMEA控制程序文件編制
- 藥物致癌性試驗(yàn)必要性指導(dǎo)原則
- 軟骨肉瘤護(hù)理查房
評(píng)論
0/150
提交評(píng)論