#include "entry.h"

//Abstract data type for telephone directory entry item
//implmented as an object.

void Entry::Init(KeyType AName, StringType ANumber)
//Stores AName and ANumber in a new entry.
//Pre : AName and ANumber are defined.
//Post: AName and ANumber are stored in an entry.
{
  strcpy(Name, AName);
  strcpy(Number, ANumber);
}

void Entry::ReadEntry()
//Reads a name and phone number into an entry.
//Pre : InFile is opened and FileName is defined.
//Post: Name and number are read into an entry.
{
  cout << "Name: ";
  cin >> Name;
  cout << "Number: ";
  cin >> Number;
}

void Entry::DisplayEntry()
//Displays the contents of an entry.
//Pre : The entry is defined.
//Post: Name and Number are displayed.
{
  cout << "\n";
  cout << "Name is " << Name <<"\n";
  cout << "Number is " << Number <<"\n";
}

char *Entry::GetName()
//Returns the name stored in an entry.
//Pre : Entry is defined.
//Post: Retruns name.
{
  return(Name);
}

char *Entry::GetNumber()
//Returns the phone number stored in an entry.
//Pre : Entry is defined.
//Post: Retruns phone number.
{
  return(Number);
}

int Entry::EqualTo(Entry AnEntry)
//Determines whether Entry key matches AnEntry key.
//Pre : Entry object and AName are defined.
//Post: Return 1 if Entry.Name = AnEntry; otherwise return 0.
{
  int Equal;
  char *AName;

   //note:  when comparing 2 strings, strncmp returns 0 if equal,
   //a number < 0 if first is greater and a number > 0 if second
   //is greater

  AName = AnEntry.GetName();
  if (strncmp(AName, Name, MaxSize) == 0)
    Equal = True;
  else
    Equal = False;

  return(Equal);
}
