ajout du calcul d'age en annee
This commit is contained in:
parent
a108668d6d
commit
1bdf07a941
2 changed files with 9 additions and 0 deletions
|
@ -18,6 +18,7 @@ public:
|
||||||
const std::string &getNom() const;
|
const std::string &getNom() const;
|
||||||
|
|
||||||
int getNaissance() const;
|
int getNaissance() const;
|
||||||
|
int getAge() const;
|
||||||
|
|
||||||
const std::string &getSexe() const;
|
const std::string &getSexe() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,4 +22,12 @@ Tortue::Tortue(const string &nom, const string &sexe) : nom(nom), sexe(sexe) {
|
||||||
naissance = std::time(nullptr);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue