-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate.cpp
More file actions
51 lines (40 loc) · 1.26 KB
/
date.cpp
File metadata and controls
51 lines (40 loc) · 1.26 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
#include <iostream>
class Date {
private:
int day;
int month;
int year;
public:
// Constructor
Date(int d, int m, int y) : day(d), month(m), year(y) {}
// Setter methods
void setDay(int d) { day = d; }
void setMonth(int m) { month = m; }
void setYear(int y) { year = y; }
// Getter methods
int getDay() const { return day; }
int getMonth() const { return month; }
int getYear() const { return year; }
// Function to check if a year is a leap year
bool isLeapYear() const {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
return true;
else
return false;
}
};
int main() {
// Create a Date object
Date myDate(1, 1, 2024);
// Use getter methods to access attributes
std::cout << "Day: " << myDate.getDay() << std::endl;
std::cout << "Month: " << myDate.getMonth() << std::endl;
std::cout << "Year: " << myDate.getYear() << std::endl;
// Check if the year is a leap year
if (myDate.isLeapYear()) {
std::cout << myDate.getYear() << " is a leap year." << std::endl;
} else {
std::cout << myDate.getYear() << " is not a leap year." << std::endl;
}
return 0;
}