-
Notifications
You must be signed in to change notification settings - Fork 0
/
date-letter-month.cpp
150 lines (147 loc) · 3.13 KB
/
date-letter-month.cpp
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
#include<bits/stdc++.h>
using namespace std;
enum monthnum
{
January=1,February=2,March=3,April=4,May=5,June=6,July=7,August=8,September=9,October=10,November=11,December=12
}realmonth;
struct date
{
int year;
char month[13];
int day;
}stu;
int main()
{
cout<<"Enter the date."<<endl;
cout<<"Month:";
cin>>stu.month;
cout<<"Date:";
cin>>stu.day;
cout<<"Year:";
cin>>stu.year;
bool run;
int yeardiv1,yeardiv2,yeardiv3;
yeardiv1=stu.year%4;
yeardiv2=stu.year%100;
yeardiv3=stu.year%400;
if(((yeardiv1==0)&&(yeardiv2!=0))||((yeardiv1==0)&&(yeardiv2==0)&&(yeardiv3==0))) run=1;
else run=0;
int daylength=0,i=1;
daylength+=stu.day;
if(stu.month[0]=='J')
{
if(stu.month[1]=='a')
{
realmonth=January;
}
else if(stu.month[1]=='u')
{
if(stu.month[2]=='n')
{
realmonth=June;
}
else if(stu.month[2]=='l')
{
realmonth=July;
}
}
}
else if(stu.month[0]=='F')
{
realmonth=February;
}
else if(stu.month[0]=='M')
{
if(stu.month[2]=='y')
{
realmonth=May;
}
else if(stu.month[2]=='r')
{
realmonth=March;
}
}
else if(stu.month[0]=='A')
{
if(stu.month[1]=='p')
{
realmonth=April;
}
else if(stu.month[1]=='u')
{
realmonth=August;
}
}
else if(stu.month[0]=='S')
{
realmonth=September;
}
else if(stu.month[0]=='O')
{
realmonth=October;
}
else if(stu.month[0]=='N')
{
realmonth=November;
}
else if(stu.month[0]=='D')
{
realmonth=December;
}
while(i<realmonth)
{
if(run==1)
{
switch(i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
daylength+=31;
break;
case 4:
case 6:
case 9:
case 11:
daylength+=30;
break;
case 2:
daylength+=29;
break;
default:
break;
}
i++;
}
else
{
switch(i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
daylength+=31;
break;
case 4:
case 6:
case 9:
case 11:
daylength+=30;
break;
case 2:
daylength+=28;
break;
}
i++;
}
}
cout<<stu.month<<" "<<stu.day<<","<<stu.year<<" is the "<<daylength<<" day of this year."<<endl;
}