#include <iostream>
#include <string>

using namespace std;

class Student {
   private:
     char *name;
   public:
     Student();
     Student(char *thename, int theage);
     Student(Student &other); // copy constructor
     ~Student();
     int age;
     void print();
};

/* good ol 1970's function
void print(Student s) {
   cout << "Name: " << s.name << "\n";
   cout << "Age: " << s.age << "\n";
} 
*/

Student::Student() {
   cout << "Called: Student()\n";
   name = new char[50];
   strcpy(name, "Noname");
   age = 20;
};

Student::Student(char *thename, int theage) {
   cout << "Called: Student(char *thename, int theage)\n";
   name = new char[strlen(thename)+1];
   strcpy(name, thename);
   age = theage;
}

Student::Student(Student &other) {
   cout << "Called: copy constructor Student(Student& other)\n";
   name = new char[strlen(other.name)+1];
   strcpy(name, other.name);
   age = other.age;
}

Student::~Student() {
   cout << "Called: ~Student()\n";
   delete[] name;
}

void Student::print() {
   cout << "Name: " << name << "\n";
   cout << "Age: " << age << "\n";
}

int main(int argc, char* argv[]) {
   Student s("Jose", 19);
   s.print();
   
   s.age = 20;
   s.print();  
   
   Student *p = new Student("Diana", 16);
   p->print();
   delete p;
   
   Student s2 = s;
   s2.print();
   
   Student r("Jenny", 21);
   r.print(); 
}
