-
大小: 229KB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2021-06-06
- 語言: C/C++
- 標(biāo)簽:
資源簡(jiǎn)介
這是我買的一本課程設(shè)計(jì)案例書上的源代碼,上面的案例很經(jīng)典,特別適合于作
畢業(yè)設(shè)計(jì)的學(xué)生使用,當(dāng)然了,也可以做為做課程設(shè)計(jì)的學(xué)生以參考,希望能給
大家提供幫助!!

代碼片段和文件信息
//設(shè)計(jì)哈希表實(shí)現(xiàn)電話號(hào)碼查詢系統(tǒng)
#include??
//nclude?“string.h“?
#include?“fstream“?//fstram=ifstream+ofstream?文件的輸入輸出
#define?NULL?0?
unsigned?int?key;?
unsigned?int?key2;?
int?*p;?
struct?node?//定義結(jié)構(gòu)體類型
{?
char?name[8]address[20];?
char?num[11];?
node?*?next;?
};?
typedef?node*?pnode;?//為類型定義新名稱
typedef?node*?mingzi;?
node?**phone;?
node?**nam;?
node?*a;?
using?namespace?std;?//使用名稱空間?
void?hash(char?num[11])?//以電話號(hào)碼為關(guān)鍵字建立哈希表
{?
int?i?=?3;?
key=(int)num[2];?
while(num[i]!=NULL)?
{?
key+=(int)num[i];?
i++;?
}?
key=key%20;?//用除留取余法獲得關(guān)鍵碼
}?
void?hash2(char?name[8])?//以用戶名為關(guān)鍵字建立哈希表
{?
int?i?=?1;?
key2=(int)name[0];?
while(name[i]!=NULL)?
{?
key2+=(int)name[i];?
i++;?
}?
key2=key2%20;?
}?
node*?input()?//輸入節(jié)點(diǎn)?
{?
node?*temp;?
temp?=?new?node;?
temp->next=NULL;?
cout<<“輸入姓名:“< cin>>temp->name;?
cout<<“輸入地址:“< cin>>temp->address;?
cout<<“輸入電話:“< cin>>temp->num;?
return?temp;?
}?
int?apend()?//添加節(jié)點(diǎn)?
{?
node?*newphone;?//結(jié)構(gòu)體指針
node?*newname;?
newphone=input();?
newname=newphone;?
newphone->next=NULL;?
newname->next=NULL;?
hash(newphone->num);?
hash2(newname->name);?
newphone->next?=?phone[key]->next;?
phone[key]->next=newphone;?
newname->next?=?nam[key2]->next;?
nam[key2]->next=newname;?
return?0;?
}?
void?create()?//新建電話號(hào)碼
{?
?
phone=new?pnode[20];?//動(dòng)態(tài)創(chuàng)建對(duì)象數(shù)組
for(int??i=0;i<20;i++)?
{?
phone[i]=new?node;?
phone[i]->next=NULL;?
}?
}?
void?create2()?//新建用戶名
{?
nam=new?mingzi[20];?//動(dòng)態(tài)創(chuàng)建對(duì)象數(shù)組
for(int?i=0;i<20;i++)?
{?
nam[i]=new?node;?
nam[i]->next=NULL;?
}?
}?
void?list()?//根據(jù)電話號(hào)顯示列表
{??
node?*p;?
for(int?i=0;i<20;i++)?
{?
p=phone[i]->next;?
while(p)?
{?
cout<name<<‘_‘<address<<‘_‘<num< p=p->next;?
}?
}?
}?
void?list2()?//根據(jù)用戶名顯列表
{??
node?*p;?
for(int?i=0;i<20;i++)?
{?
p=nam[i]->next;?
while(p)?
{?
cout<name<<‘_‘<address<<‘_‘<num< p=p->next;?
}?
}?
}?
void?find(char?num[11])?//根據(jù)電話號(hào)碼查找用戶信息
{?
hash(num);?
node?*q=phone[key]->next;?
while(q!=?NULL)?
{?
if(strcmp(numq->num)==0)//比較num和q->num
break;?
q=q->next;?
}?
if(q)?
cout<name<<“_“?<address<<“_“<num< else?cout<<“無此記錄“< }?
void?find2(char?name[8])?//根據(jù)用戶名查找用戶信息
{?
hash2(name);?
node?*q=nam[key2]->next;?
while(q!=?NULL)?
{?
if(strcmp(nameq->name)==0)?//比較name和q>name
break;?
q=q->next;?
}?
if(q)?
cout<name<<“_“?<address<<“_“<num< else?cout<<“無此記錄“< }?
void?save()?//保存用戶信息?
{?
?
node?*p;?
for(int?i=0;i<20;i++)?
{?
p=phone[i]->next;?
while(p)?
{?
fstream?iiout(“out.txt“?ios::out);?//可以向該文件輸出數(shù)據(jù)
iiout<name<<“_“<address<<“_“<num< p=p->next;?
}?
}?
}?
void?menu()?//菜單函數(shù)
{?
cout<<“******用哈希表實(shí)現(xiàn)電話號(hào)碼查詢系統(tǒng)******“< cout<<“*********歡迎進(jìn)入本系統(tǒng)*****************“< cout<<“1.添加記錄“< cout<<“2.查找記錄“< cout<<“3.姓名散列“< cout<<“4.號(hào)碼散列“< cout<<“5.清空記錄“< cout<<“6
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????544868??2009-12-24?08:15??計(jì)科0801?第十六組\用哈希表實(shí)現(xiàn)電話號(hào)碼查詢系統(tǒng).exe
?????文件???????4219??2009-02-25?15:03??計(jì)科0801?第十六組\哈希表的設(shè)計(jì)與實(shí)現(xiàn)??.cpp
?????文件?????293888??2010-06-20?00:08??計(jì)科0801?第十六組\課程設(shè)計(jì)報(bào)告書??.doc
?????文件??????49664??2010-06-20?00:09??計(jì)科0801?第十六組\數(shù)據(jù)結(jié)構(gòu)與算法課程設(shè)計(jì)任務(wù)書-.doc
?????目錄??????????0??2009-02-25?17:44??計(jì)科0801?第十六組
-----------?---------??----------?-----??----
???????????????892639????????????????????5
評(píng)論
共有 條評(píng)論