Course Home: http://blog.csdn.net/sxhelijian/article/details/11890759, complete teaching program and resources link
"Project 3-oop Edition Electronic Dictionary" (the relevant documents required by this program, please go to http://pan.baidu.com/s/1qW59HTi to download.) )
Make a simple e-dictionary.
In the file dictionary.txt. It is a dictionary of English-Chinese comparison. The vocabulary is nearly 8,000, the English, Chinese explanation and the part of speech with ' \ t ' separate.
programming, the user input English words, show the part of speech and Chinese interpretation.
Tip 1:Assuming that the dictionary is finished with OOP (and can also be implemented using the Oo method), it is possible to define a word class that represents an entry in which the data member is a string of English, a Chinese word, a string, and a corresponding Chinese meaning. String Word_class; Represents the part of speech of the word; You can also define a dictionary class to represent a dictionary. The word words[8000] member represents the entry in the dictionary, int wordsnum, and the number of entries in the dictionary. The entry is read from the file in the constructor, and a member function is specifically added to look up the word.
Tip 2:the words in the file have been sorted. So when looking for it. Use the binary search method to improve the efficiency.
Tip 3:such projects. Preferably organized in multiple files
See the answer: http://blog.csdn.net/sxhelijian/article/details/28230293
"Project 3 expand 1 (choose to do)" to make this dictionary. Read an article and output an explanation of the words in it. For example, to Aboutcpp.txt. The output, for example, is seen in the following left-hand image (see also where improvements are being made).
Explore 1 Answers:
#include <fstream> #include <iostream> #include <string> #include <cstdlib>using namespace std ;//Definition Term class Word{public:void set (string e, String C, string wc); int compare (string); The English part is more than the given string. equals return. Greater than return, less than return-1 string Getchinese (); String Getword_class ();p rivate:string 中文版; String Chinese; string Word_class;}; void Word::set (String e, String C, string wc) {english=e; Chinese=c; WORD_CLASS=WC;} int Word::compare (string k) {return english.compare (k);} String Word::getchinese () {return chinese;} String Word::getword_class () {return word_class;} Defines the dictionary class dictionary{public:dictionary (); String Searchword (string k);p rivate:int binseareh (int low, int. High, String k); int wordsnum; Word words[8000]; Used to save the thesaurus};D ictionary::D ictionary () {string E,C,WC; wordsnum=0; Read the data in the file into an array of objects Ifstream infile ("Dictionary.txt", ios::in); Open the file as input if (!infile)//test successfully opened {cerr<< "DictionarY Open error! " <<endl; Exit (1); } while (!infile.eof ()) {infile>>e>>c>>wc; Words[wordsnum].set (E, C, WC); ++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;//find successful return} if (Words[mid].compare (key) >0) High=mid-1; Continue in W[low. Find else low=mid+1 in mid-1]; Continue to find} return-1 in W[mid+1..high]; When Low>high indicates that the lookup interval is empty, the lookup fails}string dictionary::searchword (string key) {int low=0,high=wordsnum-1; The initial value of the current search interval, the lower bound int Index=binseareh (low, high, key); if (index>=0) return Words[index].getword_class () +words[index].getchinese (); else return "find no such word";} int main () {Dictionary dict; Ifstream txtfile ("Aboutcpp.txt", ios::in); Open the file as input if (!txtfile)//test successfully opened {cerr<< "text File Open error!" <<endl; Exit (1); } string Word; Unknown origin words while (Txtfile>>word) {cout<<word<< "<------" <<dict.searchword (word) <&L T;endl; } txtfile.close (); return 0;}
"Project 3 expansion 2 (optional)" Trial wxwidgets do a form version of the electronic dictionary. For example, the image below looks like this:
================= Helijian csdn Blog column ================= |== It Student Growth Guide Column column category folder (not regularly updated) ==| |== C + + Classroom Online Column The course teaching link (sub-course grade) ==| |== I wrote the book-"The reverse of the university-to the positive energy of IT students" ==| ===== the runway for it novices to take off. University ===== with students to enjoy happiness and passion |
C + + 15th week (Spring) Project 3-oop Edition electronic Dictionary (ii)