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

using namespace std;

class PGStudent : public Student {

   int gyear;
   char* first_degree;

public:
   PGStudent(const char* nam, const char* fd, int gy = 0)
      : Student(nam), gyear(gy)
   {  first_degree = new char[strlen(fd)+1];
      strcpy(first_degree,fd);
      cout << "A PGstudent was just constructed " << endl; }

// CAREFUL: copy constructor is needed
   PGStudent(const PGStudent& pgs) : Student(pgs), gyear(pgs.gyear)
   {  first_degree = new char[strlen(pgs.first_degree)+1];
      strcpy(first_degree,pgs.first_degree);
      cout << "A PGstudent was just created by copying ... "
           << endl; }

// CAREFUL: assignment needs redefinition
//          (alternative implementation if visibility is redesigned
//          Student data members were qualified as "protected")
   PGStudent& operator=(const PGStudent& pgs)
   {  if (this != &pgs) {
//         this->Student::operator=(pgs);
         Student::operator=(pgs);
         gyear = pgs.gyear;
         delete[] first_degree;
         first_degree = new char[strlen(pgs.first_degree)+1];
         strcpy(first_degree,pgs.first_degree);
         cout << "I just performed a PGstudent ASSIGNMENT ... "
              << endl;
      }
      return *this; }

   ~PGStudent()
   {  cout << "Deleting postgraduate student with name "
           << get_name() << endl;
      delete[] first_degree; }

   int get_year() const
   {  return gyear; }

   void print() const
   {  Student::print();
      cout << "First degree is: " << first_degree << endl; }
};

int main()
{
///*
   PGStudent pgs("FN1","FDEGR");
   pgs.print();

   PGStudent pgs2(pgs);
   pgs2.set_name("The New Name");

   pgs = pgs2;


//*/
// Student* ps= new PGStudent("FN2","FDEGR2");
// delete ps;

   cout << "Printing from Main:" << endl;

// Student s("FirstLast");

// s.print();
// pgs.print();
// pgs.Student::print();

/////////////////////////////////////////////
// Student* ps=&s;
// PGStudent* ppgs=&pgs;

// ps->print();
// ppgs->print();
// ppgs->Student::print();

/////////////////////////////////////////////
// Student* ss[2];

// ss[0] = &s;
// ss[1] = &pgs;

// ss[0]->print();
// ss[1]->print();

// ss[0] = new Student("TestedSt");
// ss[1] = new PGStudent("TestPSt","FDeg");

// delete ss[0];
// delete ss[1];

/////////////////////////////////////////////
///*
 Student* p1 = new Student("TestSt");
 Student* p2 = new PGStudent("TestPSt","FDeg");

 p1->print();
 p2->print();

 delete p1;
 delete p2;
//*/

   return 0;
}
