// person.cc   Example base class to illustrate inheritance
// P. Conrad for CISC220, 06J

#include "person.h"


Person_C::Person_C(const char * const theFname,
		   const char * const theLname,
		   int theId)
{
  fname = new char[strlen(theFname) + 1];
  strcpy(fname, ""); /* for TDD */
  // strcpy (fname, theFname);

  lname = new char[strlen(theLname) + 1];
  strcpy(lname, ""); /* for TDD */
  // strcpy (lname, theLname);

  id = 0; /* for TDD */
  // id = theId;

}

Person_C::Person_C(const Person_C & orig)
{
  fname = new char[strlen(orig.fname) + 1];
  strcpy(fname,""); /* temp for TDD */
    // strcpy (fname, orig.fname);

  lname = new char[strlen(orig.lname) + 1];
  strcpy(lname,""); /* temp for TDD */
  //  strcpy (lname, orig.lname);

  id = 0; /* temp for TDD */
  // id = theId;

}

Person_C & Person_C::operator =(const Person_C & right)
{
  // check for self-assignment

  if (&right == this)
    return (*this);

  // recycle old storage
  delete [] fname;
  delete [] lname;
  fname = lname = NULL;  // to avoid dangling refs

  // allocate new storage and copy values

  fname = new char[strlen(right.fname) + 1];
  strcpy (fname, ""); /* temp for TDD */
  // strcpy (fname, right.fname); 

  lname = new char[strlen(right.lname) + 1];
  strcpy (lname, "");  /* temp for TDD */
  // strcpy (lname, right.lname);

  id = 0;  /* temp for TDD */
  // id = right.id;
  
  // return reference to self to enable chaining (e.g. a = b = c;)

  return (*this);

}

Person_C::~Person_C()
{
  delete [] fname;
  delete [] lname;
  
  // next line not strictly needed, but helpful for debugging
  // makes sure that dangling refs cause a seg fault

  fname = lname = NULL; 
}


void Person_C::print(std::ostream & out) const
{
  out << id << " " << fname << " " << lname;
}

// the following illustrates that the parameters don't have to be
// right and left---here we use "where and what" instead.

std::ostream & operator << (std::ostream & where, 
			    const Person_C & what)
{
  what.print(where);
  return (where);
}




