14th Week on-machine practical Project 3--Electronic Dictionary

Source: Internet
Author: User

Make a simple e-dictionary. In the document Dictionary.txt, the preservation is a English-Chinese control dictionary, the vocabulary quantity nearly 8,000, English, the Chinese explanation and the part of speech uses ' \ t ' separates.

Code

#include <iostream> #include <fstream> #include <cstdlib>using namespace Std;class dictionary;class        Word{public:word () {} void Set (String e,string c,string W) {english=e;        Chinese=c;    Word_class=w;    } friend class dictionary;private:string 中文版;    String Chinese; string Word_class;};    Class Dictionary{public:dictionary ();    void Searchword (string en);    int midsearch (int low,int high,string key);p Rivate:int Wordnum; Word word[8000];};    Dictionary::d ictionary () {fstream infile;    String e,c,w;    wordnum=0;    Infile.open ("Dictionary.txt", ios::in);        if (!infile) {cout<< "dictionary.txt can ' t open" <<endl;    Exit (1);        } while (!infile.eof ()) {infile>>e>>c>>w;        Word[wordnum].set (E,C,W);    wordnum++; } infile.close ();}    int dictionary::midsearch (int low,int high,string key) {int mid;     while (Low<=high) {mid= (Low+high)/2;   if (Word[mid].english==key) return mid;        else if (Word[mid].english>key) high=mid-1;    else low=mid+1; } return-1;}    void Dictionary::searchword (string en) {int key=midsearch (0,wordnum-1,en); if (key) cout<<word[key].english<< "-" <<word[key].word_class<< "\ T" <<word[key].    word_class<<endl; else cout<< "look no such word!" "<<endl;}    int main () {dictionary D;    string W;    cout<< "Please enter the word you want to find:" <<endl;    while (cin>>w) {D.searchword (w); } return 0;}


14th Week on-machine practical Project 3--Electronic Dictionary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.