当前位置:文档之家› 通讯录设计报告

通讯录设计报告

C程序设计报告系(部、中心)姓名学号专业班级课程名称设计题目名称起止时间成绩指导教师签名目录第1章题目与要求 (3)1.1 基本要求(及格 (3)1.2 高级要求(加分)... (3)第2章用户需求分析 (3)2.1 功能需求 (3)第3章设计方案 (3)3.1设计思路 (3)3.2功能设计 (3)第4章实施方案 (4)第5章软件调试 (5)5.1 错误介绍 (5)5.2 错误分析及解决方案 (5)第6章程序流程图及结构说明 (6)第7章程序清单 (7)第8章效果展示 (18)第1章题目与要求本次程序设计实践的题目是《通信录管理系统的设计》。

1.1基本要求(及格)(1)使用C语言,设计一个字符界面并带有菜单的通信录管理系统,每个记录中应包含:姓名、性别、年龄、联系电话、电子邮箱等项目。

(2)最大记录数:100。

(3)程序基本功能:显示记录、添加记录、删除记录。

1.2高级要求(加分)(1)以多文件方式设计该程序。

(2)对程序中的数据类型进行自定义(为方便程序的阅读和管理,定义自己的类型名)。

(3)能将该通讯录制作成文件保存于磁盘。

第2章用户需求分析2.1 功能需求通过《程序设计实践I(能源11-12)》指导书中的相关要求,以及参考程序流程图的基本程序的框架,同时用户需求的基本功能,要求系统需要有以下功能:(1)有菜单选择界面;(2)联系人信息修改简单方便,支持多种方式的修改;(3)方便的联系人信息查询,支持多种方式的查询;(4)联系人信息查看功能能供用户详细的查看;(5)退出时若用户更改了联系人相关信息或添加、删除联系人时,会提示用户联系人信息已更改是否保存;(8)有动态的开始界面。

第3章设计方案3.1 设计思路为了更好地实现上述内容,此程序采用了结构体、链表,来处理联系人的数据。

结构体能够包含联系人的各项信息,如姓名、家庭地址、电话号码等,克服了数组只能包含同种类型的数据的缺点。

链表数据的存放不需要连续的内存,相对于结构体数组减少了内存空间的浪费。

利用fopen等函数创建文件、保存文件数据等,实现退出程序后联系人的数据能够保存,方便以后的查看、添加、修改等动作。

采取多文件的方式,能够更好地对程序进行维护调试。

3.2 功能设计本程序一共有13个子文件,共11个模块,有实现9项功能。

(1)创建联系人列表模块能够建立新的文件,实现联系人的分类存放,方便用户的对联系人的管理。

(2)添加功能能够打开已有的文件,用户需选择添加的联系人所在的文件,事先联系人的分类存放,方便以后的查看修改等操作。

添加完成后,程序将自动的进行排序操作。

(3)删除联系人选择此功能后,用户需要选择要删除联系人所在文件,再行删除。

提醒用户是否保存设置。

(4)修改联系人信息选择此功能后,用户需要选择要删除联系人所在文件,再进行各项修改。

提示用户是否保存修改。

(5)查询联系人信息用户选择了打开的文件后,可以按照姓名、手机号等对联系人进行查找。

然后打印在屏幕上。

(6)查看联系人列表用户只需选择要查看的联系人所在的文件。

系统将自动将此文件中的所有所有人打印在屏幕上。

(7)删除文件(8)退出系统第4章实施方案(1)数据结构采用链表,定义如下结构体用来建立节点:typedef struct LinkPerson{char name[20],mobile[15];char home_ph[15],E_mail[40],work_units[40];char qq[11];struct LinkPerson *next;}LP;将此结构体的typedef式的名字是LP。

next是是结构体指针,用来指向下一节点,保证链表的连续性,最后一个节点的next=NULL,作为链表的结束标志。

(2)建立链表部分代码如下:里面的所有变量已经在函数中声明while(1){n++;if(n==1) head->next=p1;else p2->next=p1;p2=p1;p1=(struct LinkPerson *)malloc(LEN);printf("姓名\n");scanf("%s",p1->name);if(strcmp(p1->name,"0")==0)break;printf("手机号\n");scanf("%s",p1->mobile);printf("家庭电话\n");scanf("%s",p1->home_ph);printf("电子邮箱\n");scanf("%s",p1->E_mail);printf("班级\n");scanf("%s",p1->work_units);printf("QQ\n");scanf("%s",p1->qq);}free(p1);当用户输入的姓名为0,程序会退出链表的创建。

循环对出后,p1->next=NULL;将最后一个节点指向空(NULL),(3)文件操作本程序对文件进行的主要操作有打开、关闭、顺序读写操作。

采用fopen函数打开文件,打开方式采用了w+、r、r+,当文件不存在时采取w+方式打开能够创建一个新的文本,r用来打开已经存在的文件,当文本不存在时将对出系统。

(4)通过对以上介绍的算法的不同组合完成了整个程序的需要的函数creat()、read ()add()等。

(5)函数的衔接各个功能函数之间的衔接主要通过函数的返回值以及函数的参数。

例如完成创建功能时,第一步调用函数creat()时会产生一个结构体指针指向结构体的头,第二部在调用save ()函数时将利用creat产生的返回值完成文件的创建以及数据的保存。

其他的功能亦如此。

第5章软件的调试5.1 错误介绍(1)变量重复定义。

(2)无法统计人数,统计人数超过实际人数。

(3)进行某项功能时,出现提示,点击确定后,软件退出运行。

(4)输出联系人列表时,屏幕上出现乱码。

5.2错误分析及解决方案(1)在本程序中有全局变量n用来统计人数,当n出现问题后将不能完成统计以及排序工作,n 在编译链接时系统提示重复定义,经过查找资料后,修改的方案是,将n 的定义有在头文件中的static n 改在main.c 中 int c ;在其他文件中用extern n ;声明。

统计人数超过实际人数,经分析是read 函数里没有将n 归0,导致再次调用时又在原来的基础上操作。

(2)出现错误3的原因 在于某个函数出现死循环,经查找是由于save 函数将数据写入文件时,循环条件的不合适导致了,死循环才会出现此错误。

如果输入文件名错误时有可能导致软件自动退出,但不会出现提示。

(3)出现错误4 有两种可能。

第一种是没有文件中没有存入数据。

第二种是读数据的方式为w+导致文件重建,将原先的数据丢失。

第6章 程序流程图及结构说明6.1 程序流程图分析根据《程序设计实践I (能源11-12)》指导书中的相关要求,以及参考程序流程图的基本程序的框架,同时由我用C 设计的通讯录管理系统的功能和相关的界面,我将我的通讯录管理系统设计如图一的程序流程图。

图一第7章程序清单(1)主函数/***********ton.c******************/#include "main.h"char selete[10];int n=0;//统计联系人的个数void main(){ int sele=0;system("color 4F");printf("请耐心等待!!");load();while(1){printf("\n \2\1\t\t\t 欢迎使用通讯录管理系统\n\n");printf("\n 1.新建联系人列表2.添加联系人 3.删除 4.修改 5.查询 6.输出联系人的信息7.删除文件\n8.退出9.paixu\n请输入选择:");scanf("%d",&sele);switch(sele){case 1:{head=creat();save(head);break;}case 2:{head=add();save(head);break;}case 3:{system("cls"); head=del();save(head);break;}case 4:{system("cls");head=modify();save(head);break;}case 5:{system("cls");find();break;}case 6:{ print();break;}case 7:{delfile();break;}case 8:{exit(0);break;}case 9:{head=read();head=array(head);save(head);break;}}}}(2)子函数/***********add.c****************/#include "main.h"LP *add(void) //函数功能:增加联系人信息{LP *head,*p1,*p2;extern n;head=p2=read();while(p2->next!=NULL) //找到原先数据的终点,作为新增数据的起点 {p2=p2->next;}p1=(LP *)malloc(LEN);printf("请输入增加联系人的信息:\n");printf("姓名\n");scanf("%s",p1->name);//if(strcmp(p1->name,"0")==0)// break;printf("手机号\n");scanf("%s",p1->mobile);printf("家庭电话\n");scanf("%s",p1->home_ph);printf("电子邮箱\n");scanf("%s",p1->E_mail);printf("班级\n");scanf("%s",p1->work_units);printf("QQ\n");scanf("%s",p1->qq);// FORMAT;while(1){n++;if(n==1) head->next=p1;else p2->next=p1;p2=p1;p1=(struct LinkPerson *)malloc(LEN);printf("姓名\n");scanf("%s",p1->name);if(strcmp(p1->name,"0")==0)break;printf("手机号\n");scanf("%s",p1->mobile);printf("家庭电话\n");scanf("%s",p1->home_ph);printf("电子邮箱\n");scanf("%s",p1->E_mail);printf("班级\n");scanf("%s",p1->work_units);printf("QQ\n");scanf("%s",p1->qq);//scanf("%s%s%s%s%s%s%s%s%s",p1->name,p1->mobile,p1->office_ ph,p1->home_ph,p1->E_mail,p1->in_cities,p1->work_units,p1->address,p1->group);}p2->next=NULL;free(p1);p1=NULL;head=array(head);return (head);}/***********array.c*****************/#include "main.h"LP *array(LP *head) //函数功能:排序{ extern n;int i,j;LP *p0,*p1,*p2,*h;h=p1=p2=head;if(n<=1) return(h);for(i=0; i<n-1; i++){p1=p2=h;for(j=0; j<n-i-1; j++){p2=p1->next;if((p1==h) && strcmp(p1->name,p2->name)>0 ){h=p2;p1->next=p2->next;p2->next=p1;p0=p2;}else if( strcmp(p1->name,p2->name)>0 ){p0->next=p2;p1->next=p2->next;p2->next=p1;p0=p2;}else { p0=p1; p1=p2; p2=p2->next; }}}return(h);}/**********creat.c**************/#include"main.h"LP creat() //创建{int m=0;LP *head,*p1,*p2;printf("\n请输入通讯录联系人信息:\n\n");p2=p1=head=(struct LinkPerson *)malloc(LEN); p1->next=NULL;printf("姓名\n");scanf("%s",p1->name);printf("手机号\n");scanf("%s",p1->mobile);printf("家庭电话\n");scanf("%s",p1->home_ph);printf("电子邮箱\n");scanf("%s",p1->E_mail);printf("班级\n");scanf("%s",p1->work_units);printf("QQ\n");scanf("%s",p1->qq);while(1){m++;if(m==1) head=p1;elsep1->next=p2;p1=p2;p2=(struct LinkPerson *)malloc(LEN) ;printf("姓名\n");scanf("%s",p2->name);if(strcmp(p2->name,"0")==0)break;printf("手机号\n");scanf("%s",p2->mobile);printf("家庭电话\n");scanf("%s",p2->home_ph);printf("电子邮箱\n");scanf("%s",p2->E_mail);printf("班级\n");scanf("%s",p2->work_units);printf("QQ\n");scanf("%s",p2->qq);}p1->next=NULL;free(p2);n=m;head=array(head);return head;}/*************del.c*******************/#include "main.h"LP *del(void) //函数功能:删除信息{;char [20];LP *head,*p1,*p2;start_del:p1=p2=head=read();printf("请输入要删除的联系人姓名: ");scanf("%s",name);while( strcmp(p1->name,name)!=0 && (p1->next!=NULL) ){ p2=p1; p1=p1->next; } //找出p1指向的节点if( strcmp(p1->name,name)==0){if(p1==head) head=p1->next;elsep2->next=p1->next;printf("del: %s\n",name);free(p1);n--;printf("还有联系人%d位\n",n);}elseprintf("没有你要删除的联系人!\n");printf("\n是否继续进行删除操作? 1.是2.返回主菜单3.退出4.是否保存设置y\\n \n请输入:");scanf("%s",selete);if( strcmp(selete,"1")==0 ) goto start_del;else if( strcmp(selete,"2")==0 ) return 0;else if( strcmp(selete,"n")==0 ) return 0;else if( strcmp(selete,"3")==0 ) exit(0);else if( strcmp(selete,"y")==0 ) return head;else return(head);}/*****shanchuwenjian******/void delfile(){char file[80];printf( " 输入要删除的文件名");scanf("%s",file);//gets(file);if (remove(file)==0)printf( "已删除:%s.\n ",file);elseprintf("无法删除文件,可能是文件不存在!!");}/**************find.c**************************/#include "main.h"int find() //函数功能:查找{char select[10],home_ph[15];char name[20],mobile[15];LP *p1,*p2,*head;start_f:p1=p2=head=read();printf("按下列选项查询联系人信息\n");printf(" 1.按姓名 2.按手机号码 3.家庭电话\n 请选择:");scanf("%s",select);if( strcmp(select,"1")==0 ){printf("请输入姓名:");scanf("%s",name);while( strcmp(p1->name,name)!=0 && (p1->next!=NULL) ){ p2=p1; p1=p1->next; } //找出p1指向的节点if( strcmp(p1->name,name)==0 ){FORMAT;printf("%s %s %s %s %s %s %s %s%s\n",p1->name,p1->mobile,p1->home_ph,p1->E_mail,p1->work_units,p1->qq);}else printf("没有要查找的联系人信息!!\n");}else if( strcmp(select,"2")==0 ){printf("请输入手机号码:");scanf("%s",mobile);while( strcmp(p1->mobile,mobile)!=0 && (p1->next!=NULL) ){ p2=p1; p1=p1->next; } //找出p1指向的节点if(strcmp(p1->mobile,mobile)==0){FORMAT;printf("%s %s %s %s %s %s %s %s%s\n",p1->name,p1->mobile,p1->home_ph,p1->E_mail,p1->work_units,p1->qq);}else printf("没有要查找的联系人信息!!\n");}else if( strcmp(select,"3")==0 ){int n_n=0;printf("请输入群组:");scanf("%s",home_ph);while( strcmp(p1->home_ph,home_ph)!=0 && (p1->next!=NULL) ) { p2=p1; p1=p1->next; } //找出p1指向的节点if(strcmp(p1->home_ph,home_ph)==0){FORMAT;printf("%s %s %s %s %s %s %s %s%s\n",p1->name,p1->mobile,p1->home_ph,p1->E_mail,p1->work_units,p1->qq);}else printf("没有要查找的联系人信息!!\n");}else { printf("\n请输入正确的选择!!\n"); goto start_f; }printf("\n 1.继续查找2.返回主菜单3.退出\n请选择:");scanf("%s",select);if( strcmp(select,"1")==0 ) goto start_f;else if( strcmp(select,"2")==0 ) return 0;else if( strcmp(select,"3")==0 ) exit(0);else return 0;}/********************load.c*********************/#include"main.h"#include "windows.h"char l[]="load.....";void load(){int i=0,a=0;while(i<3){system("cls");while(l[a]!='\0'){printf("%c",l[a]);a++;Sleep(50);}a=0;i++;Sleep(50);}system("cls");}/**************modify.c***************/#include "main.h"LP *modify() //函数功能:修改联系人信息{char name[20];int select;LP*p2,*head,*p1;start_mod:p1=p2=head=read();printf("请输入要修改的联系人姓名: ");scanf("%s",name);while( strcmp(p1->name,name)!=0 && (p1->next!=NULL) ) { p2=p1; p1=p1->next; } //找出p1指向的节点if( strcmp(p1->name,name)==0 ){printf("将要修改的联系人的信息\n");FORMAT;printf("%s %s %s %s %s %s\n",p1->name,p1->mobile,p1->home_ph,p1->E_mail,p1->work_units,p1->qq);printf("请输入要修改的选项\n");printf(" 1.姓名\t 2.手机\t 3.家庭电话\t 4.电子邮箱\n 5.班级\t6.QQ\n请输入:");scanf("%d",&select);printf("请输入该项新的信息:");if(select==1) { scanf("%s", p1->name); }if(select==2) { scanf("%s",p1->mobile); }//if(select==3) { scanf("%s",p1->office_ph); }if(select==3) { scanf("%s",p1->home_ph); }if(select==4) { scanf("%s",p1->E_mail); }//if(select==6) { scanf("%s",p1->in_cities); }if(select==5) { scanf("%s",p1->work_units); }if(select==6) { scanf("%s",p1->qq); }//if(select==9) { scanf("%s",p1->group); }///save(head);}else { printf("\n没有该联系人,请重新输入!\n\n"); goto start_mod;}printf("\n是否继续进行修改操作? 1.是2.返回主菜单3.退出4.是否保存y\n \n请输入:");scanf("%s",selete);if( strcmp(selete,"1")==0 ) goto start_mod;else if( strcmp(selete,"2")==0 ) return 0;else if( strcmp(selete,"3")==0 ) exit(0);else if( strcmp(selete,"n")==0 ) return 0;else if( strcmp(selete,"y")==0 ) return head;}/***********print.c*************/#include"main.h"void print() //函数功能:输出信息{LP *p1,*head;extern n;p1=head=read();printf("共有联系人%d 名\n\n",n);FORMAT;if(head!=NULL)do{printf("\n%s %s %s %s %s%s\n",p1->name,p1->mobile,p1->home_ph,p1->E_mail,p1->work_units,p1->qq);p1=p1->next;}while(p1!=NULL);}/******************reead.c******************/#include"main.h"LP *read(void) //函数功能:读取文件{FILE *fp;LP *head=NULL, *p1=NULL, *p2=NULL;int m=0;extern n;n=0;printf("请输入要打开的文件");scanf("%s",infile);if ((fp=fopen(infile, "r"))==NULL){ printf("Can not open this file!\n"); exit(0); }while(!feof(fp)){p1=(LP *)malloc(LEN);fscanf(fp,"%s%s%s%s%s%s\n",p1->name,p1->mobile,p1->home_ph,p1->E_mail,p1->work _units,p1->qq);m+=1;n++;if(m==1) head=p1;else p2->next=p1;p2=p1;}p2->next=NULL;fclose(fp);return head;}/***********save.c**************/#include "main.h "void save(LP *head) //函数功能:保存文件{FILE *out;LP *p1=head;char outfile[30];printf("请输入要保存的文件!\n");scanf("%s",outfile);out=fopen(outfile, "w+");if (out==NULL){ printf("Can not open this file!\n"); exit(0); }fclose(out);if ((out=fopen(outfile, "r+"))==NULL){ printf("Can not open this file!\n"); exit(0); }while(p1!=NULL){fprintf(out,"%s\t%s\t%s\t%s\t%s\t%s\n",p1->name,p1->mobile,p1->home_ph,p1->E_mail,p1 ->work_units,p1->qq);p1=p1->next;}fclose(out);}头文件/***********main.h**************/#ifndef _MIAN_H_#define _MIAN_H_#include "stdio.h"#include "stdlib.h"#include "string.h"//#include "conio.h"#define LEN sizeof(struct LinkPerson)#define FORMAT printf("姓名手机家庭电话电子邮箱班级QQ") //int n=0;//统计联系人的个数static char infile[30];extern char selete[10];//姓名、手机、办公电话、家庭电话、电子邮箱、所在省市、工作单位、家庭住址,群组分类(亲属、同事、同学、朋友、其他)typedef struct LinkPerson{char name[20],mobile[15];char home_ph[15],E_mail[40],work_units[40];char qq[11];struct LinkPerson *next;}LP;LP *head;void print();LP *creat() ;void save(LP *head); //函数功能:保存文件LP *read(void); //函数功能:读取文件LP *array(LP *head); //函数功能:排序void print(); //函数功能:输出信息LP *add(void); //函数功能:增加联系人信息LP *del(void); //函数功能:删除信息LP *modify(); //函数功能:修改联系人信息int find(); //函数功能:查找void load();void delfile();#endif第8章效果展示图2 动画启动界面程序运行界面图3 功能列表功能1新建联系人列表图4 功能2添加联系人功能3 删除联系人图6图7功能4修改图8 功能5 查询功能能实现多种方式查询图9 功能6 输出联系人图10功能7 删除文件图11 204未删除图12功能9 退出系统。

相关主题