Write the program in C++, which has two classes one, is Date having members (day, month, year) and the other class is called Employee with attribute age. The employee has Date class as member as each employee has Date of joining.
a. Determine if an employee joined the organization within last five years if the current year is 2012.
b. Determine if an Employee has age less than 40 years?
#include <iostream>
class Data
{
public:
int getDay() { return m_day; }
void setDay(int day) { m_day = day; }
int getMonth() { return m_month; }
void setMonth(int month) { m_month = month; }
int getYear() { return m_year; }
void setYear(int year) { m_year = year; }
private:
int m_day{ 1 };
int m_month{ 1 };
int m_year{ 2012 };
};
class Employee
{
public:
int getAge() { return m_age; }
void setAge(int age) { m_age = age; }
Data m_data;
void checkAge()
{
if (getAge() < 40)
{
std::cout << "The employee is under 40 years old" << std::endl;
}
else
{
std::cout << "The employee's age is over 40 years old" << std::endl;
}
}
void checkTiimeEntry(Data d)
{
int delta;
delta = (d.getDay()-m_data.getDay() +
30 * (d.getMonth() - m_data.getMonth()) +
360 * (d.getYear() - m_data.getYear())) / 360;
if (delta < 0)
{
std::cout << "Difference is negative Incorrectly entered dates"<<std::endl;
}
else if (delta < 5)
{
std::cout << "Time of joining the company is less than 5 years" << std::endl;
}
else if (delta >= 5)
{
std::cout << "Time of joining the company more than 5 years" << std::endl;
}
}
private:
int m_age{ 0 };
};
int main()
{
// Example work create emploee Bob
Employee Bob;
Bob.setAge(45);
Bob.m_data.setDay(12);
Bob.m_data.setMonth(8);
Bob.m_data.setYear(2004);
Bob.checkAge();
// current data 01 01 2012
Data current_data;
Bob.checkTiimeEntry(current_data);
return 0;
}
Comments
Leave a comment