/* ex_4_1.c++ */
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

enum sexe_t {
	HOMME=0,
	FEMME,
	SURPRISE
};

class personne {
	int age;
	sexe_t sexe;
	string nom;
	string prenom;

	personne(const personne& p);

public:
	personne(string p="Anonyme", string n="X", int a=0, sexe_t s=SURPRISE);
	~personne();
	
	personne* operator*(const int& nb) const;
	string get_identification() const { return (prenom + " " + nom); }
	void vieillit() { age++; }
};

personne::personne(string p, string n, int a, sexe_t s) :
	prenom(p),
	nom(n),
	age(a),
	sexe(s)
{
	sexe=(s<2) ? s : (sexe_t)(2*((double)rand()/RAND_MAX));
	cout << "Création d'un" << (sexe ? "e femme" : " homme");
	cout << " : " << prenom << " " << nom << endl;
	cout << " *  " << age << " ans" << endl;
}

personne::personne(const personne& p) :
	nom(p.nom),
	prenom(p.prenom),
	age(0),
	sexe(p.sexe)
{
	cout << "Clonage de " << p.prenom << " " << p.nom << " " << endl;
}

personne::~personne() {
	cout << "Destruction de ";
	cout << prenom << " " << nom << endl;
	cout << " *  " << age << " ans" << endl;
}

personne* personne::operator*(const int& nb) const {
	if (nb<=0) 
		return NULL;

	if (nb==1)
		return new personne(*this);

	return new personne[nb](*this);
}

personne* operator*(const int& nb, const personne& p) {
	return p*nb;
};

class travailleur : public personne {
	string metier;

public:
	travailleur (string m="Profession inconnue");
	travailleur (string n, string p, int a, sexe_t s, string m);
	string get_identification() const { return ("toto"); }
	void set_metier(const char* m) { metier = m; }
	string get_representation() {return personne::get_identification()+" : "+metier; };
};

travailleur::travailleur (string n, string p, int a, sexe_t s, string m) :
	metier(m) {
}

travailleur::travailleur (string m) :
	personne (),
	metier(m) {
}

int main () {
	srand(time(NULL));
	travailleur t("Xavier", "Garreau", 25, HOMME, "ingénieur");
	travailleur t2;
	travailleur* p = new travailleur("Totoeur");
	cout << p->get_identification() << endl;
//	cout << p->get_representation() << endl;
	cout << t.get_identification() << endl;
	cout << t.get_representation() << endl;
	cout << t2.get_representation() << endl;
	t.set_metier("pigiste");
	t2.set_metier("lecteur");
	cout << t.get_identification() << endl;
	cout << t.get_representation() << endl;
	cout << t2.get_representation() << endl;
	return 0;
}
