-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data.cpp
57 lines (42 loc) · 1.03 KB
/
Data.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
#include "Data.h"
#include <iostream>
using namespace std;
Data::Data(int d, int m, int y)
{
if ( m > 0 && m <= 12 ) // validate the month
month = m;
if ( y < 0 )
year = 2000;
else
year = y;
day = Checkday(d);
}
Data::setDay( int d ){
day = Checkday(d);
}
Data::setMonth( int m ){
if ( m > 0 && m <= 12 ) // validate the month
month = m;
}
Data::setYear( int y ){
if ( y < 0 )
year = 2000;
else
year = y;
}
void Data::print() const
{
cout << day << '/' << month << '/' << year;
}
int Data::Checkday(int testday ) const
{
static const int diasPorMes[ 13 ] =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if ( testday > 0 && testday <= diasPorMes[ month ] )
return testday;
if ( month == 2 && testday == 29 && ( year % 400 == 0 ||
( year % 4 == 0 && year % 100 != 0 ) ) )
return testday;
cout << "Dia invalido (" << testday << ") configurado para 1.\n";
return 1;
}