-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathdate.cpp
More file actions
158 lines (121 loc) · 2.05 KB
/
date.cpp
File metadata and controls
158 lines (121 loc) · 2.05 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <bits/stdc++.h>
using namespace std;
static string a[]={"Jan","February","March","April","May","June","July","August","September","October","November","December"};
// int monthsInArray[]={31,28,31,30,31,30,31,30,31,30,31,30};
class Date1{
private:
int date;
int month;
int year;
public:
Date1(int d,int m,int y){
date=d;
month=m;
year=y;
}
void getDate(){
cout<<"\nEnter Date ";
cin>>date;
cout<<"\nEnter Month as integer ";
cin>>month;
cout<<"\nEnter Year ";
cin>>year;
}
int returnDate()
{
return date;
}
int getMonth()
{
return month;
}
int getYear()
{
return year;
}
void showDate(){
cout<<date<<"-"<<month<<"-"<<year<<"-";
}
int Date1::operator -(Date2 d1);
};
class Date2{
private:
int date;
string month;
int year;
public:
Date2(int d,string m,int y){
date=d;
month=m;
year=y;
}
void getDate(){
cout<<"\nEnter Date ";
cin>>date;
cout<<"\nEnter Month as string ";
cin>>month;
cout<<"\nEnter Year ";
cin>>year;
}
void showDate(){
cout<<date<<" "<<month<<", "<<year<<endl;
}
int operator -(Date1 d1);
int returnDate()
{
return date;
}
string getMonth()
{
return month;
}
int getYear()
{
return year;
}
};
int Date2::operator -(Date1 d1)
{
// assuming every month has 30 days
int days=0;
days+=abs(year-d1.getYear())*365;
// if(month=="Jan")
int m;
for(int i=0;i<12;i++)
{
if(a[i]==month)
{ m=i+1;
break;
}
}
days+=(m-d1.getMonth())*30;
days=days+(date-d1.returnDate());
return days;
}
int Date1::operator -(Date2 d1)
{
// assuming every month has 30 days
int days=0;
days+=abs(year-d1.getYear())*365;
// if(month=="Jan")
int m;
for(int i=0;i<12;i++)
{
if(a[i]==d1.getMonth())
{ m=i+1;
break;
}
}
days+=(month-m)*30;
days=days+(date-d1.returnDate());
return days;
}
int main()
{
Date1 d1(12,05,2003);
Date2 d2(11,"June",2005);
int x=d2-d1;
// int x=d1-d2;
cout<<x;
return 0;
}