#include <iostream>
#include <ctime>
using std::cout;
using std::endl;
class CDate {
private:
short month, day, year;
public:
void init(void);
void init(int m, int d, int y);
void show(void);
};
void CDate::init(void) {
struct tm *p;
time_t sec;
time(&sec);
p = localtime(&sec);
month = (short)p->tm_mon + 1;
day = (short)p->tm_mday;
year = (short)p->tm_year + 1900;
}
void CDate::init(int m, int d, int y) {
month = (short)m;
day = (short)d;
year = (short)y;
}
void CDate::show(void) {
cout << month << '-' << day << '-' << year << endl;
}
int main()
{
CDate today;
today.init();
today.show();
CDate birthday;
birthday.init(2, 27, 1966);
birthday.show();
CDate d;
d = today;
d.show();
CDate *p = &d;
p->show();
CDate &ref = d;
ref.init(5, 19, 2018);
d.show();
return 0;
}
/*
run:
5-20-2018
2-27-1966
5-20-2018
5-20-2018
5-19-2018
*/