날짜를 나타내는 Data 클래스를 정의하세요. Data클래스는 year, month, day를 멤버변수로 가지며, 생성자와 소멸자가 있습니다. 직원을 나타내는 Employee 클래스를 정의하세요. Employee클래스는 name, birthDate, hireDate, salary를 멤버변수로 가지며, 생성자는 이름, 생일, 입사일, 월급을 매개변수로 받습니다.
1) Employee객체를 생성하고, 출력해보세요. 입사일, 월급 등의 값은 적절하게 하세요.
2) 입사 후에 현재(2021년 10월)까지 받은 월급을 얼마인지 계산하세요.
#include <iostream>
#include <string>
using namespace std;
class Date
{
int year;
int month;
int day;
public:
Date() {}
Date(int y, int m, int d)
{
year = y;
month = m;
day = d;
}
~Date() {}
int getYear()
{
return year;
}
int getMonth()
{
return month;
}
int getDay()
{
return day;
}
};
class Employee
{
string name;
Date birthDate;
Date hireDate;
int salary;
public:
Employee(string n, Date b, Date h, int s)
{
name = n;
birthDate = b;
hireDate = h;
salary = s;
}
void show()
{
cout << "name:" << name << endl;
cout << "birthDate:" << birthDate.getYear() << "."
<< birthDate.getMonth() << "."
<< birthDate.getDay() << endl;
cout << "hireDate:" << hireDate.getYear() << "."
<< hireDate.getMonth() << "."
<< hireDate.getDay() << endl;
cout << "salary:" << salary << endl;
}
int totalSalary(Date today)
{
int y = today.getYear() - hireDate.getYear();
int m = today.getMonth() - hireDate.getMonth();
return ((y * 12) + m) * salary;
}
};
int main()
{
Employee emp("홍길동", Date(1985, 5, 8), Date(2020, 12, 10), 250);
emp.show();
cout << emp.totalSalary(Date(2021, 10, 1)) << endl;
return 0;
}

'C++' 카테고리의 다른 글
[C++] 클래스를 이용한 파일입출력 (0) | 2022.03.25 |
---|---|
[C++] 도형 클래스 (0) | 2022.03.24 |
[C++] 스마트폰 클래스 (0) | 2022.03.22 |
[C++] 행과 열의 합계 (0) | 2022.03.21 |
[C++] 평균, 최대값, 최소값 (0) | 2022.03.20 |