// File: student_constr.cpp
#include <cstring>
#include <iostream>
using namespace std;
#include "student_constr.h"

//////////////////////////////////////////////////////////
void Student::set_name(const char* nam)
{
   delete[] name;
   name = new char[strlen(nam)+1];
   strcpy(name,nam);
}

void Student::set_no(int n)
{
   no = n;
}

void Student::set_year_of_studies(int y)
{
   year_of_studies = y;
}

void Student::set_date(int d, int m, int y)
{
   RegistrationDate.set(d,m,y);
}

//////////////////////////////////////////////////////////
char* Student::get_name() const
{
   return name;
}

int Student::get_no() const
{
   return no;
}

int Student::get_year_of_studies() const
{
   return year_of_studies;
}

void Student::get_date(int& d, int& m, int& y) const
{
   RegistrationDate.get(d,m,y);
}

//////////////////////////////////////////////////////////
Student::~Student()
{
   cout << "Deleting student with name " << name << endl;
   delete[] name;
}

//////////////////////////////////////////////////////////
Student::Student(const char* nam)
{
   name = new char[strlen(nam)+1];
   strcpy(name,nam);
   cout << "A student was just constructed " << endl;
}

/////////////////////////////////////////////////////////
Student::Student(const Student& s)
// For experimentation, comment out the following initialization,
// or keep one at a time
   : RegistrationDate(s.RegistrationDate)
// : RegistrationDate(5,10)
// : RegistrationDate(5,10,2007)
{
   name = new char[strlen(s.name)+1];
   strcpy(name,s.name);
// name = s.name;     Careful: this is the result of default copy
   no = s.no;
   year_of_studies = s.year_of_studies;
// RegistrationDate = s.RegistrationDate; // Not a good idea!
                                          // Assignment!
   cout << "A student was just created by copying ... " << endl;
}

////////////////////////////////////////////////////////////
Student& Student::operator=(const Student& s)
{
// name = s.name;   Careful: this is the result
//                  of default assignment

   if (this != &s) { // Careful not to assign to itself,
                     // especially if some storage reclaim
                     // was made within the body
      delete[] name;
      name = new char[strlen(s.name)+1];
      strcpy(name,s.name);
      no = s.no;
      year_of_studies = s.year_of_studies;
      RegistrationDate = s.RegistrationDate; // Experiment with
                                    // commenting out this line
      cout << "I just performed a student ASSIGNMENT ... " << endl;
   }
   return *this;
}
