-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDate class.cpp
More file actions
94 lines (81 loc) · 1.8 KB
/
Date class.cpp
File metadata and controls
94 lines (81 loc) · 1.8 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
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
#include<iostream>
using namespace std;
class Date {
private:
int day;
int month;
int year;
public:
Date();
void setday(int d);
void setmonth(int m);
void setyear(int y);
int getday();
int getmonth();
int getyear();
bool LeapYear(Date obj1);
int SubstractDate (Date a, Date b);
~Date();
};
Date :: Date(){
//Default constructor
}
void Date :: setday(int d){
day = d;
}
void Date :: setmonth(int m){
month = m;
}
void Date :: setyear(int y){
year = y;
}
int Date :: getday(){
return day;
}
int Date :: getmonth(){
return month;
}
int Date :: getyear(){
return year;
}
bool Date :: LeapYear(Date obj1){
if( (obj1.year%4==0) && (obj1.year%400==0) || (obj1.year%100 !=0) ){
return 1;
}
else
return 0;
}
int Date :: SubstractDate (Date a, Date b){
day = a.day - b.day;
month = a.month - b.month;
year = a.year - b.year;
// cout<<" Day = "<<day<<" Month = "<<month<<" Year = "<<year<<endl;
return 0;
}
Date :: ~Date(){
}
int main(){
Date obj1;
obj1.setday(7);
obj1.setmonth(11);
obj1.setyear(2023);
cout<<"\n Object One"<<endl;
cout<<" Day = "<<obj1.getday()<<endl;
cout<<" Month = "<<obj1.getmonth()<<endl;
cout<<" Year = "<<obj1.getyear()<<endl;
cout<<" Leap year or not : "<<obj1.LeapYear(obj1)<<endl;
Date obj2;
obj2.setday(5);
obj2.setmonth(2);
obj2.setyear(2020);
cout<<"\n Object Two"<<endl;
cout<<" Day = "<<obj2.getday()<<endl;
cout<<" Month = "<<obj2.getmonth()<<endl;
cout<<" Year = "<<obj2.getyear()<<endl;
cout<<"\n After Subtraction "<<endl;
obj1.SubstractDate(obj1, obj2);
cout<<" Day = "<<obj1.getday()<<endl;
cout<<" Month = "<<obj1.getmonth()<<endl;
cout<<" Year = "<<obj1.getyear()<<endl;
return 0;
}