2020年整理数据结构课程设计通讯录查询系统的设计与实现.doc

上传人:摩西的****12 文档编号:145843934 上传时间:2020-09-23 格式:DOC 页数:13 大小:54.03KB
返回 下载 相关 举报
2020年整理数据结构课程设计通讯录查询系统的设计与实现.doc_第1页
第1页 / 共13页
2020年整理数据结构课程设计通讯录查询系统的设计与实现.doc_第2页
第2页 / 共13页
2020年整理数据结构课程设计通讯录查询系统的设计与实现.doc_第3页
第3页 / 共13页
2020年整理数据结构课程设计通讯录查询系统的设计与实现.doc_第4页
第4页 / 共13页
2020年整理数据结构课程设计通讯录查询系统的设计与实现.doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《2020年整理数据结构课程设计通讯录查询系统的设计与实现.doc》由会员分享,可在线阅读,更多相关《2020年整理数据结构课程设计通讯录查询系统的设计与实现.doc(13页珍藏版)》请在金锄头文库上搜索。

1、叫我小老虎一、需求分析1、问题描述为某个单位建立一个员工通讯录管理系统,可以方便查询每一个员工的电话与地址。设计散列表存储,设计并实现通讯录查找系统。2、基本要求a.每个记录有下列数据项:电话号码、用户名、地址;b.从键盘输入各记录,分别以电话号码为关键字建立散列表;c.采用二次探测再散列法解决冲突;d.查找并显示给定电话号码的记录;e.通讯录信息文件保存。二、概要设计1.数据结构本程序需要用到两个结构体,分别为通讯录 message以及哈希表HxList2.程序模块本程序包含两个模块,一个是实现功能的函数的模块,另一个是主函数模块。系统子程序及功能设计本系统共有三个子程序,分别是:int H

2、x(long long key,int data)/哈希函数void BulidHx(HxList &L)/建立通讯录int Search(HxList &L)/查找3. 各模块之间的调用关系以及算法设计主函数调用BulidHx以及Search函数。函数BulidHx调用函数Hx。三、详细设计1.数据类型定义typedef structchar *name;char *add;long long phonenumber;message;typedef structmessage *list;int number;/记录数HxList;2.系统主要子程序详细设计a. 建立通讯录void Buli

3、dHx(HxList &L)/建立通讯录FILE *f = fopen(E:tongxunlu.txt, w);char buf20=0,str20=0;long long key;coutL.number;L.number+=1;L.list=new messageL.number;/分配哈希表的存储空间for(int i=0;iL.number;i+)L.listi.phonenumber=-1;L.listL.number-1.name=NULL;L.listL.number-1.add=NULL;cout输入记录信息(电话号码 用户名 地址)endl;for(int i=0;ikeyb

4、ufstr;int pose=Hx(key,L.number);/获取理论上的存储位置if(L.listpose.phonenumber=-1)else/用二次探测再散列法解决冲突/12 -12 22 -22int di,count=1;xunhuan:if(count%2=0)di=-(count/2)*(count/2);elsedi=(count/2)+1)*(count/2)+1);int site=Hx(key+di,L.number);if(site=0)if(L.listsite.phonenumber=-1)pose=site;elsecount+;goto xunhuan;e

5、lse site=L.number-abs(site);if(L.listsite.phonenumber=-1)pose=site;elsecount+;goto xunhuan; L.listpose.phonenumber=key;fprintf(f,%lld,key);fprintf(f, );L.listpose.name=new charstrlen(buf)+1;strcpy(L.listpose.name,buf);fprintf(f,%s,buf);fprintf(f, );L.listpose.add=new charstrlen(str)+1;strcpy(L.listp

6、ose.add,str);fprintf(f,%s,str);fprintf(f,n);b.查找int Search(HxList &L)/查找long long key;coutkey;int pose=Hx(key,L.number);/计算理论上的位置if(L.listpose.phonenumber=key)elseint count=1,di;/二次探测再散列,查找xunhuan:if(count%2=0)di=-(count/2)*(count/2);elsedi=(count/2)+1)*(count/2)+1);int site=Hx(key+di,L.number);if(s

7、ite=0)if(L.listsite.phonenumber=key)pose=site;elsecount+; if(L.listsite.phonenumber=-1) cout没有找到endl; return -1;/没有找到 goto xunhuan;else site=L.number-abs(site);if(L.listsite.phonenumber=key)pose=site;elsecount+; if(L.listsite.phonenumber=-1) cout没有找到endl; return -1;/没有找到 goto xunhuan;if(L.listpose.p

8、honenumber=key) cout电话号码t用户名t地址endl; coutL.listpose.phonenumbertL.listpose.nametL.listpose.addendl; return pose;四、测试与分析1.显示主菜单,运行程序可以显示出如下界面。2.建立通讯录 在主菜单下选1,建立通讯录,按照规定格式输入电话号码姓名以及地址,即可在E盘根目录下建立tongxunlu.txt文件,保存通讯录信息。 3.查找在主菜单下选2,完成查找功能,输入要查找的电话号码,即可得到该电话号码对应的姓名以及地址。 4.退出系统在主菜单下选3,退出程序。五、附录1.通讯查询系统.

9、h#includeusing namespace std;typedef structchar *name;char *add;long long phonenumber;message;typedef structmessage *list;int number;/记录数HxList;int Hx(long long key,int data)return key%(data-1);void BulidHx(HxList &L)/建立通讯录FILE *f = fopen(E:tongxunlu.txt, w);char buf20=0,str20=0;long long key;coutL.

10、number;L.number+=1;L.list=new messageL.number;/分配哈希表的存储空间for(int i=0;iL.number;i+)L.listi.phonenumber=-1;L.listL.number-1.name=NULL;L.listL.number-1.add=NULL;cout输入记录信息(电话号码 用户名 地址)endl;for(int i=0;ikeybufstr;int pose=Hx(key,L.number);/获取理论上的存储位置if(L.listpose.phonenumber=-1)else/用二次探测再散列法解决冲突/12 -12 22 -22int di,count=1;xunhuan:if(count%2=0)di=-(count/2)*(count/2);elsedi=(count/2)+1)*(count/2)+1);int site=Hx(key+di,L.number);if(site=0)if(L.listsite.phonenumber=-1)pose=site;elsecount+;goto xunhuan;else site=L.number-abs(site);if(L.listsite.phonenumber=-1)pose=site;elsecount+;goto xunhuan;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号