#include "teacher.h"
#include <iostream>
#include <fstream>
#include <cstring>
#include "leakdetection.h"
#ifdef MEMORY_LEAK_DETECTION
#define DEBUG_NEW new(__FILE__, __LINE__)
#define new DEBUG_NEW
#endif
using namespace std;
CTeacher::CTeacher()
{
m_dSalary = 0;
m_pName = new char[MAX_NAME_LENGTH];
}
CTeacher::CTeacher(const CTeacher &input)
{
m_nID = input.m_nID;
m_dSalary = input.m_dSalary;
m_pName = new char[MAX_NAME_LENGTH];
strcpy(m_pName, input.m_pName);
}
CTeacher::CTeacher(double salary)
{
m_pName = NULL;
m_dSalary = salary;
}
double CTeacher::GetSalary()
{
return m_dSalary;
}
void CTeacher::SetID(int nID)
{
m_nID = nID;
}
void CTeacher::GetName(char pName[])
{
strcpy(pName, m_pName);
}
void CTeacher::SetName(char pName[])
{
strcpy(m_pName, pName);
}
ostream& operator<<(ostream& os, const CTeacher& input)
{
os << input.m_pName
<< endl
<< input.m_dSalary
<< endl
<< input.m_nID
<< endl;
return os;
}
CTeacher& CTeacher::operator=(const CTeacher &input)
{
if(&input == this)
{
return *this;
}
delete [] m_pName;
m_dSalary = input.m_dSalary;
m_pName = new char[MAX_NAME_LENGTH];
m_nID = input.m_nID;
strcpy(m_pName, input.m_pName);
return *this;
}
istream& operator>>(istream& is, CTeacher &input)
{
if(input.m_pName == NULL)
{
input.m_pName = new char[MAX_NAME_LENGTH];
}
is.getline(input.m_pName, MAX_NAME_LENGTH);
is.ignore();
is >> input.m_dSalary >> input.m_nID;
is.ignore();
return is;
}
CTeacher::~CTeacher()
{
delete [] m_pName;
}
bool operator==(const CTeacher& lhs, const CTeacher &rhs)
{
// check if either is null, we shouldn't compare strings
// using strcmp if they're null
if(rhs.m_pName == NULL || lhs.m_pName == NULL)
{
if(rhs.m_pName == NULL && lhs.m_pName == NULL &&
(lhs.m_dSalary == rhs.m_dSalary) &&
(lhs.m_nID == rhs.m_nID))
{
return true;
}
else
{
return false;
}
}
if((lhs.m_dSalary != rhs.m_dSalary) ||
(lhs.m_nID != rhs.m_nID) ||
strcmp(rhs.m_pName, lhs.m_pName))
{
return false;
}
return true;
}
bool operator!=(const CTeacher& lhs, const CTeacher &rhs)
{
return !(lhs == rhs);
}