問題及**:
main.cpp
/*
*檔名稱:test.cpp
*完成日期:2023年06月10日
*版本號:v1.0
**問題描述:做乙個簡單的電子詞典。在檔案dictionary.txt中,儲存的是英漢對照的乙個詞典,詞彙量近8000個,英文、中文釋義與詞性間用』\t』隔開。
(1)程式設計序,由使用者輸入英文詞,顯示詞性和中文釋義。
提示1:如果要用oop完成這個詞典(當然也可以用oo方法實現),可以定義乙個word類表示乙個詞條,其中的資料成員string english; 表示英文單詞,string chinese;表示對應中文意思,string word_class;表示該詞的詞性;還可以定義乙個dictionary類,用來表示詞典,其中word words[8000]成員表示詞典中的詞條,int wordsnum;表示詞典中的詞條數,在建構函式中從檔案讀入詞條,而專門增加乙個成員函式用於查單詞。
提示2:檔案中的詞彙已經排序,故在查詢時,用二分查詢法提高效率。
提示3:這樣的專案,最好用多檔案的形式組織
*輸入描述:略
*程式輸出:略
*/#include #include #include "diction.h"
using namespace std;
class word;
class dictionary;
int main()
}while(-1);
cout<<"歡迎再次使用!"<
diction.h
#ifndef diction_h_included
#define diction_h_included
#include using namespace std;
class word
;class dictionary
;#endif // diction_h_included
diction.cpp
#include #include #include #include "diction.h"
void word::set(string e, string c, string w)
int word::compare(string k)
string word::getchinese()
string word::getword_class()
dictionary::dictionary()
infile.close();
}int dictionary::binseareh(int low, int high, string key)
if(words[mid].compare(key)>0)
high=mid-1; //繼續在w[low..mid-1]中查詢
else
low=mid+1; //繼續在w[mid+1..high]中查詢
}return -1; //當low>high時表示查詢區間為空,查詢失敗
}void dictionary::searchword(string key)
{ int low=0,high=wordsnum-1; //置當前查詢區間上、下界的初值
int index=binseareh(low, high, key);
if(index>=0)
cout<"《執行結果:
知識點總結:多檔案形式有點生疏了
學習心得:多加練習才好。
第十四周專案三 OOP版電子詞典
做乙個簡單的電子詞典。在檔案dictionary.txt中,儲存的是英漢對照的乙個詞典,詞彙量近8000個,英文 中文釋義與詞性間用 t 隔開。1 程式設計序,由使用者輸入英文詞,顯示詞性和中文釋義。提示1 如果要用oop完成這個詞典 當然也可以用oo方法實現 可以定義乙個word類表示乙個詞條,其...
第十四周專案三 OOP版電子詞典
做乙個簡單的電子詞典。在檔案dictionary.txt中,儲存的是英漢對照的乙個詞典,詞彙量近8000個,英文 中文釋義與詞性間用 t 隔開 include include include includeusing namespace std 定義詞條類 class word void word ...
第十四周專案3 OOP版電子詞典
做乙個簡單的電子詞典。在檔案dictionary.txt中,儲存的是英漢對照的乙個詞典,詞彙量近8000個,英文 中文釋義與詞性間用 t 隔開。1 程式設計序,由使用者輸入英文詞,顯示詞性和中文釋義。提示1 如果要用oop完成這個詞典 當然也可以用oo方法實現 可以定義乙個word類表示乙個詞條,其...