ajout du calcul d'age en annee

This commit is contained in:
Victor Le Roch 2020-05-20 10:00:00 +02:00
parent a108668d6d
commit 1bdf07a941
2 changed files with 9 additions and 0 deletions

View file

@ -18,6 +18,7 @@ public:
const std::string &getNom() const;
int getNaissance() const;
int getAge() const;
const std::string &getSexe() const;
};

View file

@ -22,4 +22,12 @@ Tortue::Tortue(const string &nom, const string &sexe) : nom(nom), sexe(sexe) {
naissance = std::time(nullptr);
}
int Tortue::getAge() const {
int ageSec = std::time(nullptr) - naissance;
int ageHour = ageSec/(60*60);
int ageDay = ageHour/24;
int age = ageDay / 365.25;
return age;
}