C语言课程设计-通讯录管理系统资料整理_第1页
C语言课程设计-通讯录管理系统资料整理_第2页
C语言课程设计-通讯录管理系统资料整理_第3页
C语言课程设计-通讯录管理系统资料整理_第4页
C语言课程设计-通讯录管理系统资料整理_第5页
已阅读5页,还剩41页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

PAGEPAGE1中国地质大学本科生课程论文封面课程名称C语言程序设计教师姓名本科生姓名本科生学号本科生专业所在院系类别:日期:课程设计评语对课程论文的评语:平时成绩:课程论文成绩:总成绩:评阅人签名:注:1、无评阅人签名成绩无效;2、必须用钢笔或圆珠笔批阅,用铅笔阅卷无效;3、如有平时成绩,必须在上面评分表中标出,并计算入总成绩。目录课程设计评语 2目录 31.课程论文题目 42.程序设计思路 43.功能模块图 54.数据结构设计 55.算法设计 66.程序代码 137.程序运行结果 218.编程中遇到的困难及解决方法 279.总结心得及良好建议 2810.致谢 281.课程论文题目通讯录管理系统要求:设计具有数据插入、修改、删除、显示和查询功能的电话簿管理系统。⑴数据包括:人名、工作单位、电话号码和E-mail地址。⑵可对记录中的姓名和电话号码进行修改。⑶可增加或删除记录。⑷可显示所有保存的记录。⑸可按人名或电话号码进行查询。2.程序设计思路根据题目的要求,程序应该采用结构体数组和文件系统实现。应该有动态的存储空间和文件输入、输出等操作功能;在程序中应该包括添加、显示、删除、查询和修改以及保存和退出的功能;另外还应提供键盘式选择菜单实现功能选择。3.功能模块图4.数据结构设计整个程序中用到的数据主要是全局变量MAX100和字符变量name[10]、addr[20]、phnum[20]、email[20]。5.算法设计主函数主函数的设计一般比较的简单,只提供输入,功能处理和输出部分的函数调用。其中个功能模块用菜单方式选择。菜单部分也可以写成函数。[流程图][程序]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.Addapieceofmeg");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);switch(n)/*****************输入n的在1-6之间执行switch************/{case1:Add();/*添加模块*/break;case2:List();/*显示模块*/break;case3:Delete();/*删除模块*/break;case4:Find();/*查询模块:分为名字查询(0)和电话号码查询(1)*/break;case5:Alter();/*修改模块:分为修改名字(0)和修改电话号码(1)*/break; case6:exit(0);/*退出模块*/break;case7:creat();/*带回链表起始地址*/fclose(fp);default:/**********输入的n不在1-6之间执行default************/printf("\n\t********************************************\n");printf("\n\tThenumshouldbe1-6!!!\n");printf("\n\t********************************************\n");break;}}while(1);}2.各功能模块设计[数据结构]通讯录的数据信息:人名、工作单位、电话号码、E-mail地址均可以采用字符型数组;可以采用结构体的形式,把各信息作为结构的成员,由于通讯录要具有添加、查找、和删除的功能,所以整个通讯录采用链表比较容易的实现以上功能。用结构体变量作为链表中的接点是最合适的。结构体变量可以是指针类型,我们可以用这个指针类型的成员来存放下一个结点的地址。结构体的类型如下:structpersons{typedefstructp{charname[10]charname[10];charaddr[20];charaddr[20];charphnum[20];charphnum[20];charemail[20];charemail[20];}persons[MAX];structp*next;}p,*linklist;structpersons类型为每个链表成员;typedefstructp为一个动态的结点,它的成员next存放下一个结点的地址。以下为各模块分析时要用的指针:linklisthead=NULL,t=NULL;/**************定义头指针和尾指针*************/p*s,*p0,*p1,*p2,*p3,*p4,*p5;inti;charname1[10],ch;charstr1[20];FILE*fp;/********************定义文件指针***********************/(1)输入模块[程序]voidcreat()/*将文件的信息读入结构体数组在转存入链表中*/{intj;longk;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;/*****不能打开另开辟一个文件*****/}}⑵添加模块由于运用的是链表的形式,且通讯录只是按照输入的先后循序排序,所以对添加的信息采用插入末端的方式,同时添加也使用于空通讯录的信息输入。[程序]voidAdd()/*******向通讯录中添加(或输入)一个人的信息*********/{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)head=s;/*******若通讯录为空则添加在头指针之后相当于输入信息*********/else{t->next=s;/***********添加到链表的末尾************/t=s;}}⑶显示模块链表的一大好处是只要定义了头指针,则所有的信息就很容易的找到,指针会一环扣一环的找到每个信息,显示出每个信息,直到最后到位指针结束。[程序]voidList()/*****************显示所有的信息*******************/{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向后移一个位置*****************/}}⑷删除模块删除一个人的信息相当于是删除链表中的一个结点。在删除后又要保证链表不间断,如同手牵手排队的小孩,一个离队后,它两侧的小孩又自动地把手牵起来,保证不间断即把结点从链表中分离开来,只要撤销原来的链表关系即可。[流程图]要删除地信息p1->nexxtp1=p1->nextp2=p1p1->nexxtp1=p1->nextp2=p1[程序]voidDelete()/************定义一个删除的函数***************/{charname0[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**************Deletesuccess!******************\n");}elseprintf("\n\t**************Deletefail!******************\n");/*没找到要删除的位置*/}⑸查询模块按照题目的要求查询可以分为姓名查询和电话号码查询[流程图]选择查询方式查询选择查询方式查询输入电话号码:输入姓名:输入电话号码:输入姓名:找到找到找到找到未找到提示信息未找到提示信息找到的提示信息找到的提示信息未找到提示信息未找到提示信息找到的提示信息找到的提示信息[程序]voidFind()/***********定义一个查询的函数**************/{intn;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**************Cannotfindthemessage!**********");}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);}}elseif(n==1)/***************电话号码查询***************/{printf("\n\tphnum1");p3=head;gets(phnum1);scanf("%s",&phnum1);/****************输入电话号码***************/while((strcmp(phnum1,p3->phnum)!=0)&&(p3!=NULL))/*根据各种情况判断可能性*/p3=p3->next;if(p3->phnum==NULL)/***************没有找到**************/{printf("\n\t************Cannotfindthemessage!***********");}elseif(strcmp(phnum1,p3->phnum)==0)/******找到信息并输出******/{printf("\n\n\t**********Foundthemessage:*********");printf("\n\tname:%s",p3->name);⑹修改模块按照题目的要求查询可以分为修改姓名和修改电话号码,修改模块的设计思路和查询模块的思路基本上相同。[流程图]修改修改修改失败输入新的电话号码提示修改成功输入新的姓名提示修改成功修改失败找到信息找到信息未找到信息未找到输入电话号码:输入姓名:修改内容修改失败输入新的电话号码提示修改成功输入新的姓名提示修改成功修改失败找到信息找到信息未找到信息未找到输入电话号码:输入姓名:修改内容 [程序]voidAlter()/***************定义一个修改的函数*****************/{intm;charphnum2[20],name2[10];printf("\n\n\t****Whichmessagedoyouwanttoalter?*******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:");canf("%s",&name2);/**********输入新的信息**********/strcpy(p4->name,name2);/*******新的姓名修改成功*******/printf("\n\n\t************Alteredsuccess!************\n");}}elseif(m==1)/***************修改电话号码***************/{printf("\n\tphnum:");scanf("%s",&phnum2);/************输入要修改的电话号码***************/p4=head;while((strcmp(phnum2,p4->phnum)!=0)&&(p4!=NULL))/*根据各种情况判断可能性*/p4=p4->next;if(p4==NULL){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************Alteredsuccess!************\n");}}}⑺保存模块[程序]voidSave()/************定义一个保存信息的函数************/{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(structpersons),1,fp);}}6.程序代码#include<stdio.h>#include<stdlib.h>#include<string.h>#defineMAX100structpersons{charname[10];charaddr[20];charphnum[20];charemail[20];}persons[MAX];typedefstructp{charname[10];charaddr[20];charphnum[20];charemail[20];structp*next;}p,*linklist;linklisthead=NULL,t=NULL;p*s,*p0,*p1,*p2,*p3,*p4,*p5;inti;charname1[10],ch;charstr1[20];FILE*fp;voidcreat(){intj;longk;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;}}voidAdd(){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)head=s;else{t->next=s;t=s;}}voidList(){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;}}voidDelete(){charname0[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**************Deletesuccess!******************\n");}elseprintf("\n\t**************Deletefail!******************\n");}voidFind(){intn;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**************Cannotfindthemessage!**********");}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);}}elseif(n==1){printf("\n\tphnum1");p3=head;gets(phnum1);scanf("%s",&phnum1);while((strcmp(phnum1,p3->phnum)!=0)&&(p3!=NULL))p3=p3->next;if(p3->phnum==NULL){printf("\n\t************Cannotfindthemessage!*********");}elseif(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);}}}voidAlter(){intm;charphnum2[20],name2[10];printf("\n\n\t****Whichmessagedoyouwanttoalter?****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************Alteredsuccess!************\n");}}elseif(m==1){printf("\n\tphnum:");scanf("%s",&phnum2);p4=head;while((strcmp(phnum2,p4->phnum)!=0)&&(p4!=NULL))p4=p4->next;if(p4==NULL){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************Alteredsuccess!************\n");}}}voidSave(){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(structpersons),1,fp);}}main(){intn;creat();do{printf("\n\t***********************************************\n");printf("\n\n\t*************WELCOMETOUSE!***************\n");printf("\n\t**********************************

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论