-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalender.cpp
More file actions
137 lines (127 loc) · 3.15 KB
/
calender.cpp
File metadata and controls
137 lines (127 loc) · 3.15 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
#include<iostream>
using namespace std;
int main()
{
int td,tm,ty,num,n;
cout<<"Enter today's date in dd mm yyyy format:"<<endl;
cin>>td>>tm>>ty;
cout<<"Press the corresponding number to perform the following operation:"<<endl<<"1 : Date calculator"<<endl<<"2 : Age calculator"<<endl<<"3 : Week calculator"<<endl;
cin>>n;
switch(n)
{
case 1:
{
int days;
cout<<"Welcome!"<<endl<<"Enter the number of days preceeding which you want the date:"<<endl;
cin>>days;
while(days>0)
{
if((ty%100==0 && ty%400==0))
{
num=29;
}
else if(ty%100!=0 && ty%4==0)
num=29;
else
{
num=28;
}
int arr[]={31,num,31,30,31,30,31,31,30,31,30,31};
if((arr[tm-1]-td)>days)
{
cout<<td+days<<"/"<<tm<<"/"<<ty<<endl;
break;
}
else
{
days=days-(arr[tm-1]-td);
}
while(days>0)
{
while(tm<12)
{
if(arr[tm]>days)
{
cout<<days<<"/"<<tm+1<<"/"<<ty<<endl;
days=0;
break;
}
else
{
days=days-arr[tm];
tm++;
}
}
break;
}
tm=tm-11;
td=0;
ty++;
if(days==0)
break;
}
break;
}
case 2:
{
cout<<"Enter your birth date in dd/mm/yyyy format:"<<endl;
int bd,bm,by,years,months,days;
cin>>bd>>bm>>by;
years=ty-by-1;
months=(12-bm)+(tm-1);
int arr[]={31,num,31,30,31,30,31,31,30,31,30,31};
days=(arr[bm-1]-bd+1)+td;
if(days>30)
{
days=days-30;
months++;
}
if(months>12)
{
months=months-12;
years++;
}
cout<<years<<" "<<"Years"<<endl<<months<<" "<<"Months"<<endl<<days<<" "<<"Days"<<endl;
break;
}
case 3:
{
int dd,j;
cout<<"Enter no of days after which you want day of week:"<<endl;
cin>>dd;
string wk;
cout<<"Enter today's day of week:"<<endl;
cin>>wk;
string week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
for(int i=0;i<7;i++)
{
if(wk==week[i])
{
j=i;
}
}
while(dd!=0)
{
for(j;j<7;j++)
{
if(dd==0)
{
cout<<week[j];
break;
}
dd--;
}
for(int k=0;k<j;k++)
{
if(dd==0)
{
cout<<week[k];
break;
}
dd--;
}
}
}
}
return 0;
}