added age calculation.
This commit is contained in:
parent
5a44a57bee
commit
ad4052c2b5
@ -22,6 +22,20 @@ public:
|
||||
Date(short day, short month, unsigned int year) : day(day), month(month), year(year)
|
||||
{
|
||||
}
|
||||
|
||||
double get_age()
|
||||
{
|
||||
struct tm newtime;
|
||||
__time64_t long_time;
|
||||
_time64(&long_time);
|
||||
auto err = _localtime64_s(&newtime, &long_time);
|
||||
if(err)
|
||||
{
|
||||
printf("Invalid argument to _localtime_s");
|
||||
return 0;
|
||||
}
|
||||
return newtime.tm_year - (year - 1900);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -32,7 +46,8 @@ public:
|
||||
Employee(string name, string first_name, short day, short month, unsigned int year) : name(move(name)), first_name(move(first_name)), taken_holidays(0)
|
||||
{
|
||||
day_of_birth = Date(day, month, year);
|
||||
holidays = 30;
|
||||
auto age = day_of_birth.get_age();
|
||||
holidays = age > 50 ? 32 : 30;
|
||||
}
|
||||
|
||||
string name;
|
||||
|
Loading…
x
Reference in New Issue
Block a user