#include <iostream.h>
#include <fstream.h>
#include <algorithm>
#include <functional>
#include <vector>
#include "person.h"

typedef vector<Person*> Cont;
typedef Cont::iterator Itor;

template <class T> struct printPtr : public unary_function<T, void>
{
  printPtr(ostream& out) : os(out) {}
  void operator() (T x) { os << *x  << endl; }
  ostream& os;
};cou

struct personEq : public binary_function<Person*, Person*, bool>
{
  bool operator() (Person* p1, Person* p2) 
    { return p1->Name() == p2->Name(); }
};

struct changePerson : public unary_function<Person*, void>
{
  void operator() (Person* p) {
    string input;

    cout << p->Name() << ". Enter new name: ";
    getline(cin,input);
    if (input != "")
      p->setName(input);
  }
};

void fillCont(Cont& c, char fname[])
{
  ifstream f;
  Person* p;

  f.open(fname);

  p = new Person;
  f >> *p;

  while(f) {
    c.push_back(p);
    p = new Person;
    f >> *p;
  }
  f.close();
}

main()
{
  Cont c1,c2;

  fillCont(c1,"data.txt");
   
  fillCont(c2,"data.txt");

  pair<Itor,Itor> result = mismatch(c1.begin(),c1.end(),c2.begin(),personEq());
  if (result.first ==  c1.end())
    cout << "Point 1: No mismatch" << endl;
  else
    cout << "Point 1: MISMATCH" << endl;

  for_each(c2.begin(),c2.end(),changePerson());

  result = mismatch(c1.begin(),c1.end(),c2.begin(),personEq());
  if (result.first ==  c1.end())
    cout << "Point 2: No mismatch" << endl;
  else
    cout << "Point 2: MISMATCH - " << **(result.second) << endl;
  


}

