Monday, May 24, 2010

How to create a dictionary using C++ programming language?

need to use file, class, pointer

How to create a dictionary using C++ programming language?
___________





// Here is some skeleton code; you can flesh out the specifics:





#include%26lt;iostream%26gt;


#include%26lt;fstream%26gt;


#include%26lt;string%26gt;





using namespace std;





class Dictionary


{


private:





char alphabet;


string meaning;


string word;





public:





void getmeaning(std::string *p);





void search()


{


string word;





cout%26lt;%26lt;"enter a word :";


cin%26gt;%26gt;word;





getmeaning(%26amp;word);


}


}di;











void Dictionary::getmeaning(std::string *p)


{


string a,b;





// Assume there exists a dictionary dic.txt


// Remember to add proper error handling (file operation)


ifstream get("dic.txt",ios::in);





while ( !get.eof())


{


get%26gt;%26gt;a%26gt;%26gt;b;





if (*p==a){


cout%26lt;%26lt;a%26lt;%26lt;" "%26lt;%26lt;b;


}


}


}











int main(){


int ch;








cout%26lt;%26lt;"=D=I=C=T="%26lt;%26lt;endl;


cout%26lt;%26lt;"1.Show meaning"%26lt;%26lt;endl;


cout%26lt;%26lt;"2.Show word"%26lt;%26lt;endl;


cout%26lt;%26lt;"3.Exit"%26lt;%26lt;endl;


cin%26gt;%26gt;ch;





switch(ch)


{


case 1:


di.search();





break;


case 2:


string word;





cout%26lt;%26lt;"enter a word :";


cin%26gt;%26gt;word;





di.getmeaning(word);





break;


case 3 :


return 0;


}


___________





EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT


___________





What is a Map?





The map container class provides the programmer with a convenient way to store and retrieve data pairs consisting of a key and an associated value. Each key is associated with one value. (If you want to associate a key with more than one value, look up the multimap container class.)








A working C++ dictionary program. It makes use of the Find() function:





Description: http://cis.stvincent.edu/html/tutorials/...





Code: http://cis.stvincent.edu/html/tutorials/...








Note: don't forget to include code in case the user enters a search word that is not in the dictionary.





___________

crab apple

No comments:

Post a Comment