-
Notifications
You must be signed in to change notification settings - Fork 23
/
19.Ex2 WordAndMeaning.cpp
43 lines (34 loc) · 989 Bytes
/
19.Ex2 WordAndMeaning.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <set>
#include <iostream>
#include <string>
using namespace std;
struct PAIR_WORD_MEANING
{
string word;
string meaning;
PAIR_WORD_MEANING(const string& sWord, const string& sMeaning)
: word(sWord), meaning(sMeaning) {}
bool operator<(const PAIR_WORD_MEANING& pairAnotherWord) const
{
return(word < pairAnotherWord.word);
}
bool operator==(const string& key)
{
return(key == this->word);
}
};
int main()
{
multiset <PAIR_WORD_MEANING> msetDictionary;
PAIR_WORD_MEANING word1("C++", "A programming language");
PAIR_WORD_MEANING word2("Programmer", "A geek!");
msetDictionary.insert(word1);
msetDictionary.insert(word2);
cout << "Enter a word you wish to find the meaning of" << endl;
string input;
getline(cin, input);
auto element = msetDictionary.find(PAIR_WORD_MEANING(input, ""));
if(element != msetDictionary.end())
cout << "Meaning is: " <<(*element).meaning << endl;
return 0;
}