// acct.cc  Linked List of Names and Acct Numbers.
// P. Conrad    04/04/05

#include "acct.h"
#include <cstring> // for strncpy
using std::strncpy;

Acct_C::Acct_C(int theAcctNum, const char *theName)
{
  acctNum = theAcctNum;
  setName(theName);
}

Acct_C::Acct_C(const Acct_C &orig) // copy constructor
{
  // default memberwise copy would have worked for acctNum
  acctNum = orig.acctNum;

  // but for name, better use a strncpy
  strncpy(name, orig.name, NAME_MAX); 
}


Acct_C & Acct_C::operator=(const Acct_C & right) // assignment
{
  if (this == &right) // self assignment
    return *this;

  acctNum = right.acctNum;
  strncpy(name, right.name, NAME_MAX);
  
  return (*this);
}

int Acct_C::getAcctNum() const
{
  return acctNum;
}

const char * Acct_C::getName() const
{
  return name;
}

void Acct_C::setAcctNum(int theAcctNum)
{
  acctNum = theAcctNum;
}

void Acct_C::setName(const char *theName)
{
  strncpy(name,theName,NAME_MAX-1);
  name[NAME_MAX-1]=0;  // or = '\0';
}

std::ostream & operator << (std::ostream & left, const Acct_C & right)
{
  right.print(left);
  return left;
}
