-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDate.h
131 lines (116 loc) · 2.75 KB
/
Date.h
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
/** Date class to handle dates in a C++ code.
*
* #include "Date.h" <BR>
* -llib
*
*/
#ifndef DATE_H
#define DATE_H
// SYSTEM INCLUDES
#include<iostream>
#include <ctime>
// Date class definition
class Date {
public:
// LIFECYCLE
/** Default + Overloaded constructor.
*/
Date(int = 0, int = 0, int = 0);
// Use compiler-generated copy constructor, assignment, and destructor.
// Date(const Date&);
// Date& operator=(const Date&);
// ~Date();
// OPERATORS
/** Stream Insertion operator.
*
* @param os Standard Output Stream.
* @param from The value to be inserted to the output stream.
*
* @return A reference to the standard output stream.
*/
friend std::ostream& operator <<(std::ostream& os, const Date& from);
/** Stream Extraction operator.
*
* @param is Standard Intput Stream.
* @param to The value to be extracted from the input stream.
*
* @return A reference to the standard input stream.
*/
friend std::istream& operator >>(std::istream& is, Date& to);
// OPERATIONS
/** Add 'X' no. of days to the date object.
*
* @param x The no. of days to be added.
*
* @return void
*/
void AddDay(int x = 0);
/** Add 'X' no. of months to the date object.
*
* @param x The no. of months to be added.
*
* @return void
*/
void AddMonth(int x = 0);
/** Add 'X' no. of years to the date object.
*
* @param x The no. of years to be added.
*
* @return void
*/
void AddYear(int x = 0);
/** Calculate age in years till to date.
*
* @param void
*
* @return calculated age in years.
*/
double CaclAge();
// ACCESS
// setters
void SetDay(int = 0);
void SetMonth(int = 0);
void SetYear(int = 0);
void SetDate(int = 0, int = 0, int = 0);
/**
# @overload void SetDate(const Date& aDate)
*/
void SetDate(const Date&);
/**
# static function that sets default date
*/
static void sSetDefaultDate(int = 0, int = 0, int = 0);
// getters
int GetDay()const;
int GetMonth()const;
int GetYear()const;
const Date& GetDate()const;
static const Date& sGetDefaultDate();
static Date sGetTodaysDate();
private:
// INQUIRY
/** utility function to confirm proper day value based on month and year.
* Also handles leap years.
*
* @param testDay The day to be tested.
*
* @return true if testDay is correct, false otherwise.
*/
bool CheckDay(int testDay)const;
/** Check for leap year
*
* @param testYear The year to be tested for leap years.
*
* @return true if testYear is a leap year, false otherwise.
*/
bool IsLeapYear(int testYear)const;
// DATA MEMBERS
int mDay;
int mMonth;
int mYear;
// class variable shared by all objects of date class
static Date msDefaultDate;
};
// end class Date
#endif
// _DATE_H_