/* ex_3_3.c++ */ #include #include #include using namespace std; enum sexe_t { HOMME=0, FEMME, SURPRISE }; struct personne { int age; sexe_t sexe; string nom; string prenom; void affiche(); void vieillit() { age++; } personne(string p="Anonyme", string n="X", int a=0, sexe_t s=SURPRISE); ~personne(); }; personne::personne(string p, string n, int a, sexe_t s) { nom=n; prenom=p; age=a; 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() { cout << "Destruction de "; cout << prenom << " " << nom << endl; cout << " * " << age << " ans" << endl; } int main () { srand(time(NULL)); personne persX("Xavier", "Garreau", 25, HOMME); personne persG("Guillaume", "Garreau", 21, HOMME); persG.vieillit(); return 0; }