-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.cpp
More file actions
46 lines (33 loc) · 871 Bytes
/
Copy pathData.cpp
File metadata and controls
46 lines (33 loc) · 871 Bytes
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
#include "Data.h"
#include <iostream>
#include <time.h>
using std::cout;
Data::Data(int d, int m, int a)
{
if ( m > 0 && m <= 12 ) // validate the month
mes = m;
if ( a < 0 )
ano = 1900;
else
ano = a;
dia = VerificaDia(d);
}
void Data::print() const
{
cout << dia << '/' << mes << '/' << ano;
}
int Data::VerificaDia(int diaTeste) const
{
static const int diasPorMes[ 13 ] =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if ( diaTeste > 0 && diaTeste <= diasPorMes[ mes ] )
return diaTeste;
if ( mes == 2 && diaTeste == 29 && ( ano % 400 == 0 ||
( ano % 4 == 0 && ano % 100 != 0 ) ) )
return diaTeste;
cout << "Dia invalido (" << diaTeste << ") configurado para 1.\n";
return 1;
}
int Data::getAno() const {
return ano;
}