//listpers.cpp
//uses a list to hold person objects
#include<iostream>
#include<list>
#include<algorithm>
#include<string>
using namespace std;
class person
{
private:
string lastname;
string firstname;
long phonenumber;
public:
    person()://no-arg constructor
      lastname("blank"),firstname("blank"),phonenumber(0l)
      {}
      person(string lana,string fina,long pho):
lastname(lana),firstname(fina),phonenumber(pho)
{}
friend bool operator<(const person&,const person&);
friend bool operator==(const person&,const person&);
friend bool operator!=(const person&,const person&);
friend bool operator>(const person&,const person&);
void display()const //display all data
{
cout<<endl<<lastname<<",\t"<<firstname<<"\t\t phone:"<<phonenumber;
}

long get_phone()const //return phone number
{
return phonenumber;
}
};
bool operator==(const person& p1,const person& p2)
{
    return (p1.lastname==p2.lastname&&p1.firstname==p2.firstname)?true:false;
}
//overloaded<for person class
bool operator<(const person& p1,const person& p2)
{
if(p1.lastname==p2.lastname)
return (p1.firstname<p2.firstname)?true:false;
return (p1.lastname<p2.lastname)?true:false;
}
//overloaded   != for person class
bool operator !=(const person &p1,const person &p2)
{
return !(p1==p2);
}
//overloaded>for person class
bool operator>(const person& p1,const person& p2)
{
return !(p1<p2)&&!(p1==p2);}
int main()
{
list<person>perslist;
//list of persons
list<person>::iterator list;//iterator to a list of persons
//put persons in list
perslist.push_back(person("deauville","william",8435150));
perslist.push_back(person("mcdonald","stacey",3327563));
perslist.push_back(person("bartoski","peter",6946473));
perslist.push_back(person("kuangthu","bruce",4157300));
perslist.push_back(person("wellington","jhon",9207404));
perslist.push_back(person("mcdonald","amanda",8435150));
perslist.push_back(person("fredericks","roger",7049982));
perslist.push_back(person("mcdonald","stacey",7764987));
cout<<"\n number of entries= "<<perslist.size();
iterl=perslist.begin();//display contents of list
while(iterl!=perslist.end())
(*iterl++).display();
//find person or persons with specified name(last and first)
string searchlastname,searchfirstname;
cout<<"\n\n enter last name of person to search for:  ";
cin>>searchlastname;
cout<<"enter first name:  ";
cin>>searchfirstname;
//make a person with that name
person searchperson(searchlastname,searchfirstname,0l);
//search for first match of names
iter1=find(perslist.begin(),perslist.end(),searchperson);
if(iter1!=perslist.end())//find additional mathces
{
cout<<"person(s) with that name is (are)  ";
do
{
(*iter1).display();//display with
++iter1;//search again,one past match
iter1=find(iter1,perslist.end(),searchperson);
}
while(iter1!=perslist.end());
}
else
cout<<"there is no person with that name.";
//find person or persons with specified phone number
cout<<"\n\n enter phone number(format 1234567):  ";
long snumber;//get search number
cin>>snumber;
//iterate through list
bool found_one=false;
for(iter1=perslist.begin();iter1!=perslist.end();++iter1)
{
if(snumber==(*iter1).get_phone())//compare numbers
{
if(!found_one)
{
cout<<"person(s) with that phone number is (are)  ";
found_one=true;
}
(*iter1).display();//display the match
}
}
if(!found_one)
cout<<"there is no person with that phone number";
cout<<endl;
return 0;
}