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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#include <iostream>
#include <map>
#include <string>
using namespace std;
class student
{
private:
string element1;
string element2;
string element3;
public:
student( ) { element1 = element2 = element3 = " "; } // default constructor
student(string a,string b,string c):element1(a),element2(b),element3(c) {} // all elements filled
student(string a):element1(a) { element2 = element3 = " "; } // to compare element1
string e_1( ) { return element1; }
string e_2( ) { return element2; }
string e_3( ) { return element3; }
};
bool operator < (student a,student b) { return a.e_1() < b.e_1(); }
class subject
{
private:
string option;
public:
subject( ) { option =" "; }
subject(string a):option(a) {}
string str( ) { return option;}
};
typedef multimap<student,subject,less<student> > mapsub;
int main( )
{
typedef multimap<student,subject,less<student> > mapsub;
mapsub studsubj;
mapsub::const_iterator ptr;
/* 1 */ studsubj.insert(pair<student,subject>(student("we","WORK","today"), subject("option 3")));
/* 2 */ studsubj.insert(pair<student,subject>(student("you","WORK","today"), subject("option 4")));
/* 3 */ studsubj.insert(pair<student,subject>(student("THEY","do","work"), subject("option 1")));
/* 4 */ studsubj.insert(pair<student,subject>(student("THEY","read","books"), subject("option 1")));
/* 5 */ studsubj.insert(pair<student,subject>(student("THEY","work","today"), subject("option 1")));
string word_1="THEY",word_2 = "read",word_3 ="books"; // input words to сомраre with words from multimap studsubj
student st(word_1);
ptr = studsubj.find(st);
if(ptr != studsubj.end())
{
student st= ptr->first;
cout<<"st.e_1() match word_1 ( "<<word_1<<" )"<<endl;
do
{
if(st.e_2() == word_2 )
{
cout<<"st.e_2() match word_2 ( "<<word_2<<" )"<<endl;
if( st.e_3() == word_3 )
{
cout<<"st.e_3() match word_3 ( "<<word_3<<" )"<<endl;
break;
}
else
{
cout<<endl<<"word3 doesn't match word_3 ( "<<word_3<<" )"<<endl;
break;
}
} // if(st.e2() == word2 )
else
{
cout<<"st.e_2() doesn't match word_2 ( "<<word_2<<" )"<<endl;
break;
}
ptr++;
}
while(ptr != studsubj.upper_bound(word_2));
}
return 0;
}
|