ajout du calcul d'age en annee
這個提交存在於:
父節點
a108668d6d
當前提交
1bdf07a941
共有 2 個檔案被更改,包括 9 行新增 和 0 行删除
|
@ -18,6 +18,7 @@ public:
|
|||
const std::string &getNom() const;
|
||||
|
||||
int getNaissance() const;
|
||||
int getAge() 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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
載入中…
新增問題並參考