日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

项目-OOP版电子词典

發布時間:2024/3/26 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 项目-OOP版电子词典 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


問題及代碼:

/* *Copyright (c) 2016,煙臺大學計算機學院 *All rights reserved. *文件名稱:main.cpp *作 者:李磊濤 *完成時間:2016年6月23日 *版 本 號:v1.0 * *問題描述:項目-OOP版電子詞典。 *輸入描述:要查找單詞。 *程序輸出:漢語意思。 */#include <fstream> #include<iostream> #include<string> #include<cstdlib> using namespace std; class word { public:void set(string a,string b,string c);int compare(string);string getchinese();string getword_class(); private:string english;string chinese;string word_class; }; void word::set(string a,string b,string c) { english=a; chinese=b; word_class=c; } int word::compare(string k) {return english.compare(k);} string word::getchinese() {return chinese;} string word::getword_class() {return word_class; } class Dictionary { public:Dictionary();void sword(string k); private:int BinSeareh(int low, int high, string k); int wordsNum; word words[8000]; //用于保存詞庫 }; Dictionary ::Dictionary() {string a,b,c;wordsNum=0;ifstream infile("dictionary.txt",ios::in); //以輸入的方式打開文件 if(!infile) //測試是否成功打開 { cerr<<"dictionary open error!"<<endl; exit(1); } while (!infile.eof()){infile>>a>>b>>c;words[wordsNum].set(a,b,c);++wordsNum;}infile.close(); } int Dictionary::BinSeareh(int low, int high, string key) {int mid; while(low<=high) { mid=(low + high) / 2; if(words[mid].compare(key)==0) { return mid; //查找成功返回 } 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::sword(string k) { int low=0,high=wordsNum-1; //置當前查找區間上、下界的初值 int index=BinSeareh(low, high, k); if(index>=0) cout<<k<<"--->"<<words[index].getword_class()+"\t"<<words[index].getchinese(); else cout<<"查無此詞"; cout<<endl<<endl; } int main( ) { Dictionary dict; string key; do { cout<<"請輸入待查詢的關鍵詞(英文),0000結束:"<<endl; cin>>key; if (key!="0000") { dict.sword(key); } } while(key!="0000"); cout<<"歡迎再次使用!"<<endl<<endl; return 0; }

運行結果:


知識點總結:
通過該程序,強化了我對簡單程序結構的認識。
學習心得:
期間有很多小錯誤,要繼續寫程序爭取早日掌握C++。

問題及代碼:

運行結果:


知識點總結:
通過該程序,強化了我對簡單程序結構的認識。
學習心得:
期間有很多小錯誤,要繼續寫程序爭取早日掌握C++。

總結

以上是生活随笔為你收集整理的项目-OOP版电子词典的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。