include iostream using namespace std class Triad public int int int Tr

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
using namespace std;
class Triad{
public:
int a;
int b;
int c;
Triad(){ a = 0; b = 0; c = 0; }
void increment_a(){ a++; }
void increment_b(){ b++; }
void increment_c(){ c++; }
void show(){
cout << a << " " << b << " " << c << endl;
}
};
class Date :public Triad{
private:
int year;
int month;
int day;
public:
Date(int inDay, int inMonth, int inYear){
day = inDay;
month = inMonth;
year = inYear;
}
void change_date(int k){
if (k / 365 > 0) {
year = year + k / 365;
k = k - 365 * (k / 365);
}
if (k / 31 > 0){
if (month + k / 31 > 12){
month = (month + k / 31) % 12;
year = year + 1;
k = k - 31 * (k / 31);
}
else{
month = month + k / 31;
k = k - 31 * (k / 31);
}
}
if (day + k > 31){
day = (day + k) % 31;
month = month + 1;
if (month > 12){
month = 1;
year = year + 1;
}
}
else{
day = day + k;
}
}
void show_date(){
cout << day << "-" << month << "-" << year << endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Date D(12,3,1994);
D.show_date();
D.change_date(56);
D.show_date();
return 0;
}