#include<iostream>
#include <cstring>
#include"student.h"

using namespace std;

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

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

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

void Student::print() const
{
   cout << "The name of the student is: " << name << endl;
   cout << "The AM of the student is: " << no << endl;
}
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
Student::Student(const char* nam)
{
   name = new char[strlen(nam)+1];
   strcpy(name,nam);
   cout << "A student was just constructed with name: " << name << endl;
}

Student::Student(const Student& s)
                 : no(s.no)
{
   name = new char[strlen(s.name)+1];
   strcpy(name,s.name);
// name = s.name;     Careful: this is the result of default copy
   cout << "A student was just created by copying ... " << endl;
}

//////////////////////////////////////////////////////////
Student& Student::operator=(const Student& s)
{
   if (this != &s) { // Careful not to assign to itself,
                     // especially if some storage reclaim
                     // was made within the body
   // name = s.name;    Careful: this is the result
                     // of default assignment
      delete[] name;
      name = new char[strlen(s.name)+1];
      strcpy(name,s.name);
      no = s.no;
      cout << "I just performed a student ASSIGNMENT ... " << endl;
   }
   return *this;
}
//////////////////////////////////////////////////////////
Student::~Student()
{
   cout << "Deleting student with name " << name << endl;
   delete[] name;
}
