TestDateType.cpp
1.58 KB
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
73
74
75
76
77
78
79
80
#include "DateType.h"
#include <iomanip>
#include <iostream>
using namespace std;
void PrintMonth(int Month, ostream &Out) {
switch (Month) {
case 1:
Out << "January";
return;
case 2:
Out << "February";
return;
case 3:
Out << "March";
return;
case 4:
Out << "April";
return;
case 5:
Out << "May";
return;
case 6:
Out << "June";
return;
case 7:
Out << "July";
return;
case 8:
Out << "August";
return;
case 9:
Out << "September";
return;
case 10:
Out << "October";
return;
case 11:
Out << "November";
return;
case 12:
Out << "December";
return;
default:
Out << "Juvember";
}
}
void PrintDate(DateType aDate, ostream &Out) {
PrintMonth(aDate.GetMonth(), Out);
Out << ' ' << aDate.GetDay() << ", " << setw(4) << aDate.GetYear() << endl;
}
RelationType ComparedTo(DateType dateA, DateType dateB) {
if (dateA.GetYear() < dateB.GetYear())
return Precedes;
if (dateA.GetYear() > dateB.GetYear())
return Follows;
if (dateA.GetMonth() < dateB.GetMonth())
return Precedes;
if (dateA.GetMonth() > dateB.GetMonth())
return Follows;
if (dateA.GetDay() < dateB.GetDay())
return Precedes;
if (dateA.GetDay() > dateB.GetDay())
return Follows;
return Same;
}
int main() {
DateType Tomorrow(1, 18, 2002), AnotherDay(10, 12, 1885);
if (ComparedTo(Tomorrow, AnotherDay) == Same) {
cout << "what do you think?" << endl;
}
if (Tomorrow.ComparedTo(AnotherDay) == Same)
cout << "Think about it, Scarlett!" << endl;
PrintDate(Tomorrow, cout);
}