-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDate.cpp
138 lines (134 loc) · 3.48 KB
/
Date.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "Date.h"
#include <iostream>
#include <sstream>
void Date::set_Date(int day_x, int month_x, int year_x) {
this->day = day_x;
this->month = month_x;
this->year = year_x;
}
Date::Date(string s) {
stringstream ss(s);
string d, m, y;
getline(ss, d, '.');
getline(ss, m, '.');
getline(ss, y, '.');
day = stoi(d);
month = stoi(m);
year = stoi(y);
if (month < 1 || month > 12) { //îò 1 äî 12 ìåñÿöåâ
cout << "Wrong date!" << endl;
month = 1;
}
for (int i = 1; i < 12; i += 2) { //îò 1 äî 31 äíÿ
if ((month == i) && (day > 31 || day < 1)) {
cout << "Wrong date!" << endl;
if (day > 31) {
day = 31;
}
else {
if (day < 0) {
day = 1;
}
}
if (i == 7) {
i--;
}
}
}
if (year % 4 == 0 && month == 2 && day > 29) { //Âûñîêîñíûé, îò 1 äî 29 äíåé
cout << "Wrong date!" << endl;
day = 29;
if (day < 1) {
day = 1;
}
}
if (year % 4 != 0 && month == 2 && day > 28) { //Íå âûñîêîñíûé, îò 1 äî 28 äíåé
cout << "Wrong date!" << endl;
day = 28;
if (day < 1) {
day = 1;
}
}
for (int i = 4; i < 11; i += 2) { //îò 1 äî 30 äíåé
if (month == i && (day > 30 || day < 1)) {
cout << "Wrong date!" << endl;
if (day > 30) {
day = 30;
}
if (day < 1) {
day = 1;
}
}
if (i == 6) {
i++;
}
}
}
bool Date::operator==(Date& dat) {
if (day == dat.day && month == dat.month && year == dat.year) {
return true;
}
else return false;
}
string Date::get_Date() {
return (to_string(day) + '.' + to_string(month) + '.' + to_string(year));
}
Date::Date() {
day = 0;
month = 0;
year = 0;
}
Date::Date(int d, int m, int y) {
day = d;
month = m;
year = y;
if (month < 1 || month > 12) { //îò 1 äî 12 ìåñÿöåâ
cout << "Wrong date!" << endl;
month = 1;
}
for (int i = 1; i < 12; i += 2) { //îò 1 äî 31 äíÿ
if ((month == i) && (day > 31 || day < 1)) {
cout << "Wrong date!" << endl;
if (day > 31) {
day = 31;
}
else {
if (day < 0) {
day = 1;
}
}
if (i == 7) {
i--;
}
}
}
if (year % 4 == 0 && month == 2 && day > 29) { //Âûñîêîñíûé, îò 1 äî 29 äíåé
cout << "Wrong date!" << endl;
day = 29;
if (day < 1) {
day = 1;
}
}
if (year % 4 != 0 && month == 2 && day > 28) { //Íå âûñîêîñíûé, îò 1 äî 28 äíåé
cout << "Wrong date!" << endl;
day = 28;
if (day < 1) {
day = 1;
}
}
for (int i = 4; i < 11; i += 2) { //îò 1 äî 30 äíåé
if (month == i && (day > 30 || day < 1)) {
cout << "Wrong date!" << endl;
if (day > 30) {
day = 30;
}
if (day < 1) {
day = 1;
}
}
if (i == 6) {
i++;
}
}
}
Date::~Date() {};