




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、實驗報告:簡單英漢字典2011-12-22實現(xiàn)目標(biāo)及要求:1)利用散列表實現(xiàn)英漢字典;2) 實現(xiàn)散列表類,要求實現(xiàn)一種散列表:散列函數(shù)選取建議:將單詞轉(zhuǎn)成整數(shù),再用除留余數(shù)法獲得散列地址。沖突解決方法可采用開散列法。3)實現(xiàn)字典類,字典數(shù)據(jù)存放在內(nèi)存,字典類中有兩個重要數(shù)據(jù)成員:字典數(shù)組:存放字典數(shù)據(jù)的數(shù)組(或線性表)。散列表對象:作為字典數(shù)據(jù)索引的散列表。散列表元素結(jié)構(gòu)包含單詞和對應(yīng)字典數(shù)據(jù)在字典數(shù)組中的下標(biāo),可通過散列表直接獲得單詞在字典數(shù)組的下標(biāo)。4) 利用上面兩個類實現(xiàn)英漢字典。5)界面要求:鍵盤輸入單詞,屏幕輸出解釋:界面菜單項:1.添加新詞2.刪除單詞3.查字典查字典界面:請輸入英
2、文單詞:China中文翻譯:中國實驗環(huán)境與工具:使用Microsoft Visual Studio 2010 在Windows7 64位環(huán)境下進行實驗。實驗思路:分如下N步:1. 先實現(xiàn)鏈結(jié)點類的結(jié)構(gòu)。2. 實現(xiàn)字典類的結(jié)構(gòu)。3. 實現(xiàn)詞條類的結(jié)構(gòu)。4. 實現(xiàn)詞條的散列表分類方法。5. 整合功能。主要的數(shù)據(jù)結(jié)構(gòu)如下:/Hash_head.h#include<assert.h>#include<string>#include<stdlib.h>using namespace std;const int defaultDicSize=10;const int d
3、efaultTableSize=10;class ChainNodepublic:Entry<string> EntryLink;ChainNode *link;template<class E>class Dictionarypublic:Dictionary(E e);Dictionary()delete ht;bool search(string,string &);bool search(string,string &,ChainNode *&);bool insert(E);bool insert(string,string);bool
4、 remove(string);void dicPos(E e);void outputDic();private:ChainNode *ht;int dicSize;/總詞條數(shù)int tableSize;/每個索引容量;template<class E>Dictionary<E>:Dictionary(E e)/計算詞條數(shù),作為字典最大長度dicSize=0;while(edicSize.chinese!="")dicSize+;/初始化字典ht=new ChainNodedicSize;for(int i=0;i<dicSize;i+)ht
5、i.link=NULL;hti.EntryLink=Entry<string>();template<class E>void Dictionary<E>:dicPos(E e)int i;ChainNode *p;for(i=0;i<dicSize;i+)insert(ei);template<class E>bool Dictionary<E>:insert(E ent)int k;ChainNode *p1,*p2;tableSize=5;k=ent.firstLetter()%tableSize;p1=&htk;
6、if(p1->link!=NULL)p1=p1->link;while(p1->link!=NULL)p1=p1->link;p2=new ChainNode;p2->EntryLink=ent;p2->link=NULL;p1->link=p2;return 0;template<class E>bool Dictionary<E>:insert(string str1,string str2)Entry<string> *e=new Entry<string> (str1,str2);insert(*
7、e);return 1;template<class E>void Dictionary<E>:outputDic()int i;ChainNode *p1;for(i=0;i<tableSize;i+)/cout<<"*"<<endl;/cout<<i<<endl;/cout<<"*"<<endl;if(hti.link!=NULL)p1=&hti;while(p1->link!=NULL)p1=p1->link;p1->En
8、tryLink.output();/cout<<"*"<<endl;template<class E>bool Dictionary<E>:remove(string str)string result;ChainNode *ptr;if(search(str,result,ptr)=1)ptr->link=ptr->link->link;return 1;elsereturn 0; template<class E>bool Dictionary<E>:search(string s
9、tr,string &result)ChainNode *ptr;return search(str,result,ptr);template<class E>bool Dictionary<E>:search(string str,string &result,ChainNode *&ptr)int k;ChainNode *p1,*p2;Entry<string> strEnt(str);k=strEnt.firstLetter()%dicSize;p1=&htk;if(p1->link!=NULL)doptr=p1
10、;p1=p1->link;if(p1->EntryLink.word=strEnt.word)result=p1->EntryLink.chinese;return 1;while(p1->link!=NULL);return 0;elsereturn 0;/Entry_head.h#include<assert.h>#include<string>#include<stdlib.h>using namespace std;template<class K>class Entrypublic:K word;K chines
11、e;public:Entry(K,K);Entry();Entry(K);void output();int firstLetter();template<class K>Entry<K>:Entry(K w,K c)word=w;chinese=c;template<class K>Entry<K>:Entry()word=""chinese=""template<class K>Entry<K>:Entry(K w)word=w;chinese=""templ
12、ate<class K>void Entry<K>:output()cout<<"英文:"<<word<<endl;cout<<"中文:"<<chinese<<endl<<endl;template<class K>int Entry<K>:firstLetter()char *strv = strdup (word.c_str();/stringcharreturn int(strv0);主要代碼結(jié)構(gòu):/Hash_main
13、.cpp#include<iostream>#include<string>#include"Entry_head.h"#include"Hash_head.h"using namespace std;const int deafaultSize=10+1;int main()cout<<"*"<<endl;cout<<"* *"<<endl;cout<<"* 大貓哥 *"<<endl;cout<
14、;<"* Make By LJDe.de *"<<endl;cout<<"* E-mail:LJDede *"<<endl;cout<<"* *"<<endl;cout<<"*"<<endl;Entry<string> edeafaultSize=Entry<string>("eliminate","消除"),Entry<string>("a
15、ccommodation ","招待設(shè)備"),Entry<string>("convince ","使確信"),Entry<string>("conscience ","良心"),Entry<string>("lantern ","燈籠"),Entry<string>("procession ","隊伍"),Entry<string>("
16、quit","離開"),Entry<string>("pudding ","布丁"),Entry<string>("reaction ","反應(yīng)"),Entry<string>("shrink ","收縮"),Entry<string>();Dictionary< Entry<string> > dic(e);int deed;string str1,str2;Entry&l
17、t;string> *eLit;dic.dicPos(e);docout<<endl<<"*"<<endl;cout<<"1.查看已有的字典詞條。"<<endl;cout<<"2.添加新的詞條到字典。"<<endl;cout<<"3.刪除已有詞條。"<<endl;cout<<"4.查字典。"<<endl;cout<<"5.清屏。"
18、;<<endl;cout<<"6.退出程序。"<<endl;cout<<"*"<<endl;cout<<"請選擇你要進行的操作:"cin>>deed;cout<<"你選擇的操作是:"<<deed<<endl;switch(deed)case 1:cout<<endl<<"*"<<endl;dic.outputDic();break;case
19、2:cout<<endl<<"*"<<endl;cout<<"請輸入新詞條的key,為英文:"cin>>str1;cout<<endl;cout<<"請輸入該詞條的value,為中文:"cin>>str2;cout<<endl;dic.insert(str1,str2);cout<<"你輸入的詞條為:"<<endl<<endl;eLit=new Entry<string> (str1,str2);eLit->output();break;case 3:cout<<endl<<"*"<<endl;cout<<"請輸入要刪去的詞條的key,為英文:"cin>>str1;if(dic.remove(str1)cout<<"刪除成功!"<<endl;elsecout<<"刪除失敗,目標(biāo)詞條不存在"<<endl;brea
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度綜合性醫(yī)院消毒滅菌專業(yè)服務(wù)合同
- 2025年度農(nóng)業(yè)土地整治土地承包合同
- 2025年度抵押車個人車輛抵押權(quán)解除后續(xù)貸合同模板
- 寵物運輸司機勞務(wù)協(xié)議
- 2025年廣東生態(tài)工程職業(yè)學(xué)院單招職業(yè)適應(yīng)性測試題庫必考題
- 2025年二手房市場分析:二手房市場降幅收窄
- 2024年三季度報重慶地區(qū)A股主營業(yè)務(wù)利潤排名前十大上市公司
- 2024-2025學(xué)年福建省福州市馬尾第一中學(xué)等六校高二上學(xué)期期中聯(lián)考生物試卷
- 2023-2024學(xué)年湖南省衡陽市祁東縣高考考前仿真聯(lián)考三生物試卷
- 意見征詢稿回復(fù)函
- 網(wǎng)絡(luò)地址轉(zhuǎn)換NAT
- 【MOOC】營養(yǎng)學(xué)-武漢大學(xué) 中國大學(xué)慕課MOOC答案
- 工資薪金管理制度模版(3篇)
- 廣東省茂名市高州市五校聯(lián)考2024-2025學(xué)年高一上學(xué)期12月月考化學(xué)試題(含答案)
- 高等數(shù)學(xué)(二)(山東聯(lián)盟)知到智慧樹章節(jié)測試課后答案2024年秋青島科技大學(xué)
- 《高級算法設(shè)計》課件 第2章 高級圖算法
- 小兒泌尿系統(tǒng)感染的護理
- DB14∕T 92-2010 M5、M15車用甲醇汽油
- 農(nóng)村飲水協(xié)議書(2篇)
- 疼痛的護理講課課件
- 2024年高考真題-政治(江蘇卷) 含解析
評論
0/150
提交評論