Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- #include <iterator>
- using namespace std;
- class Dictionary
- {
- private:
- string DictionaryName;
- map<string,string> WordCard;
- size_t DicSize;
- public:
- Dictionary(string Name=" ",size_t size=0):DictionaryName(Name),DicSize(size)
- {
- if(DictionaryName==" ")
- {
- cout<<"введите язык словаря"<<endl;
- cin>>DictionaryName;
- }
- }
- void ChangeName(string NewName)
- {
- DictionaryName = NewName;
- }
- void ShowName()
- {
- cout<<"это словарь "<<DictionaryName<<" языка"<<endl;
- }
- void InsertWord(const string& word)
- {
- if(WordCard.empty() && DicSize!=0 && DelPair(word))
- {
- string b,a;
- cout<<"введите перевод введенного слова "<<word<<endl;
- cin>>b;
- WordCard[word]=b;
- cout<<"вы можете ввести еще "<<DicSize-1<<" слова ,"<<"введите слово и его перевод"<<endl;
- for(size_t i=0 ; i<DicSize-1 ; i++)
- {
- cin>>a>>b;
- if(DelPair(a))
- WordCard[a] = b;
- else
- {
- while(true)
- {
- cout<<"такое слово уже есть ,введтие другое слово и перевод"<<endl;
- cin>>a>>b;
- if(DelPair(a)==true)
- {
- WordCard[a] = b;
- break;
- }
- else
- continue;
- }
- }
- }
- b=" ";
- }
- else
- {
- string b;
- DicSize+=1;
- if(DelPair(word))
- {
- cout<<"введите перевод слова"<<endl;
- cin>>b;
- WordCard[word] = b;
- b=" ";
- }
- else
- { string a;
- while(true)
- {
- cout<<"такое слово уже есть ,введтие другое слово и перевод"<<endl;
- cin>>a>>b;
- if(DelPair(a)==true)
- {
- WordCard[a] = b;
- break;
- }
- else
- continue;
- }
- b=" ";
- }
- }
- }
- bool DelPair(const string& word)
- {
- map<string,string>::iterator it;
- it=WordCard.find(word);
- if(it->first==word)
- return false;
- else
- return true;
- }
- void DelWord(const string& word)
- {
- if(!WordCard.empty())
- {
- map<string,string>::iterator it;
- it=WordCard.find(word);
- if(it!=WordCard.end())
- {
- DicSize-=1;
- WordCard.erase(it);
- }
- else
- {
- cout<<"слово для удаления не найдено"<<endl;
- }
- }
- else
- {
- cout<<"в словаре нет слов"<<endl;
- }
- }
- void FindWordTanslation(const string& word)
- {
- map<string,string>::iterator it;
- it=WordCard.find(word);
- if(it!=WordCard.end())
- {
- cout<<"слово ,перевод которого вы искадли: "<<it->first<<endl;
- cout<<"искомый перевод: "<<it->second<<endl;
- }
- else
- {
- cout<<"перевод такого слова не найден "<<word<<endl;
- }
- }
- Dictionary& operator=(const Dictionary& copy)
- {
- if(this!=©)
- {
- DictionaryName = copy.DictionaryName;
- DicSize = copy.DicSize;
- WordCard = copy.WordCard;
- return *this;
- }
- else
- return *this;
- }
- Dictionary(const Dictionary& copy)
- {
- DictionaryName = copy.DictionaryName;
- DicSize = copy.DicSize;
- WordCard = copy.WordCard;
- }
- friend Dictionary operator*(const Dictionary& temp1 , const Dictionary& temp2);
- };
- Dictionary operator*(const Dictionary& temp1,const Dictionary& temp2)
- {
- map<string,string>::iterator it;
- map<string,string>::iterator it2;
- Dictionary temp;
- temp.DictionaryName = temp1.DictionaryName +" - "+ temp2.DictionaryName;
- size_t size = 0;
- for(it=temp1.WordCard.begin(); it!=temp1.WordCard.end() ; it++)
- {
- for (it2=temp2.WordCard.begin();it2!=temp2.WordCard.end() ; it2++)
- {
- if(it->second==it2->second)
- {
- temp.WordCard[it->first] = it2->first;
- size++;
- }
- }
- }
- temp.DicSize = size;
- return temp;
- }
- int main()
- {
- setlocale (LC_ALL, "Russian");
- Dictionary A("english",3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement