#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
struct ContactItem
{
string strContactsName;
string strPhoneNumber;
ContactItem(const string& strName, const string & strNumber)
{
strContactsName = strName;
strPhoneNumber = strNumber;
}
bool operator == (const ContactItem& itemToCompare) const
{
return (itemToCompare.strContactsName == this->strContactsName);
}
bool operator < (const ContactItem& itemToCompare) const
{
return (this->strContactsName < itemToCompare.strContactsName);
}
};
void FindContact(const set <ContactItem>& setContacts)
{
cout << "*** Wyszukanie danych kontaktowych ***" << endl;
cout << "Czyj numer telefonu chcialbys znalezc?" << endl;
cout << "> ";
string strName;
cin >> strName;
set <ContactItem>::const_iterator iContactFound
= setContacts.find(ContactItem(strName, ""));
if (iContactFound != setContacts.end())
{
cout << strName << " jest dostepny pod numerem telefonu: ";
cout << iContactFound->strPhoneNumber << endl;
}
else
cout << strName << " nie zostal znaleziony na liscie kontaktow" << endl;
cout << endl;
return;
}
class FindByNumber
{
string number;
public:
FindByNumber(string _number):number(_number) { }
bool operator() (const ContactItem& it) { return it.strPhoneNumber==number; }
};
void FindContactByNumber(const set <ContactItem>& setContacts)
{
cout << "Znajdz imie kontaktu po numerze telefonu!" << endl;
cout << "Wpisz numer telefonu" << endl;
cout << ">";
string strPhoneNumber;
cin >> strPhoneNumber;
auto iContactFound = find_if(setContacts.begin(), setContacts.end(), FindByNumber(strPhoneNumber));
if (iContactFound != setContacts.end())
{
cout << strPhoneNumber << " jest numerem telefonu do: ";
cout << iContactFound->strContactsName << endl;
}
else
{
cout << "Kontakt o podanym numerze telefonu nie zostal znaleziony!" << endl;
}
}
int main() {
set<ContactItem> ksiazka;
ksiazka.insert(ContactItem("Stasiu", "1234"));
FindContactByNumber(ksiazka);
return 0;
}