-
Notifications
You must be signed in to change notification settings - Fork 0
/
code
313 lines (268 loc) · 6.75 KB
/
code
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#include<fstream>
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
class calender
{
protected:
public:
virtual void show()=0;
};
class MONTH:public calender
{
protected:
int istartDay,iNumOfDays,mon_num,iyear;
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
public:
void get_month()
{
cout<<"enter the month\n";
cin>>mon_num;
cout<<"enter the startday of the month\n";
cin>>istartDay;
mon_num+=1;
}
void leap(int iyear)
{
if((((iyear%4==0)&&(iyear%100!=0))||(iyear%400==0)))
{
cout<<"LEAP YEAR\n";
month[1]=29;
}
else{
month[1]=28;
}
}
void show()
{
mon_num=mon_num-2;
cout<<"THE MONTH IS:\n";
switch(mon_num)
{
case 0:cout<<"JANUARY\n";
break;
case 1:cout<<"FEBRUARY\n";
break;
case 2:cout<<"MARCH\n";
break;
case 3:cout<<"APRIL\n";
break;
case 4:cout<<"MAY\n";
break;
case 5:cout<<"JUNE\n";
break;
break;
case 6:cout<<"JULY\n";
break;
case 7:cout<<"AUGUST\n";
break;
case 8:cout<<"SEPTEMBER\n";
break;
case 9:cout<<"OCTOBER\n";
break;
case 10:cout<<"NOVEMBER\n";
break;
case 11:cout<<"DECEMBER\n";
break;
}
cout<<"\n";
int i,x;
iNumOfDays=month[mon_num];
cout<<"The number of days in the month is:\n"<<iNumOfDays<<endl;
try{
if(istartDay < 0 || istartDay > 6 || iNumOfDays >31 || iNumOfDays <28)
throw(x);
}catch(int a){
cout<<"Invalid input\n";
exit(0);
}
cout<<"\n";
cout.width(8);
cout<<"MON";
cout.width(8);
cout<<"TUE";
cout.width(8);
cout<<"WED";
cout.width(8);
cout<<"THU";
cout.width(8);
cout<<"FRI";
cout.width(8);
cout<<"SAT";
cout.width(8);
cout<<"SUN";
cout.width(8);
cout<<"\n";
for(i=0;i<istartDay;i++)
cout.width(8);
cout<<" ";
i=1;
while(i<=iNumOfDays)
{
cout.width(8);
cout<<i;
if(0 == (i+istartDay)%7)
{
cout<<"\n";
}
i++;
}
}
int& operator[](int x)
{
if(x<=0||x>12)
{
cout<<"invalid input\n";
exit(0);
}
else
return month[x];
}
};
class LEAP
{
int leapyear;
public:
void check_leap()
{
if(leapyear%4==0)
{
if(leapyear%100==0)
{
if(leapyear%400==0)
cout<<leapyear<<"is a leap year\n";
else
cout<<leapyear<<"is not a leap year\n";
}
else
cout<<leapyear<<"is a leap year\n";
}
else
cout<<"is not a leap year\n";
}
void get_input()
{
cout<<"Enter the year to check\n";
cin>>leapyear;
}
};
class GETDAY: virtual public MONTH
{
protected:
int y1,d1,i,r,s;
char week[7][10];
public:
void get_info()
{
cout<<"Enter the day, month and year\n";
cin>>d1>>mon_num>>y1;
}
void show()
{
s=0;
strcpy(week[0],"SUNDAY");
strcpy(week[1],"MONDAY");
strcpy(week[2],"TUESDAY");
strcpy(week[3],"WEDNESDAY");
strcpy(week[4],"THURSDAY");
strcpy(week[5],"FRIDAY");
strcpy(week[6],"SATURDAY");
static int t[]={0,3,2,5,0,3,5,1,4,6,2,4};
y1-=mon_num<3;
s=(y1+y1/4-y1/100+y1/400+t[mon_num-1]+d1)%7;
cout<<"\nTHE DAY IS:\t";
cout<<week[s]<<endl;
}
};
class NOTE
{
protected:
int rday,rmonth,ryear,x;
string str;
public:
void get_date()
{
cout<<"enter the date to add a note\n";
cout<<"dd/mm/yy\n";
cin>>rday>>rmonth>>ryear;
}
void get_string()
{
cout<<"enter the string\n";
cin>>str;
}
void add()
{
ofstream fout("notes2");
fout<<str;
cout<<"Note is added\n";
fout.close();
}
void get_print(NOTE N1)
{
try
{
if(rday==N1.rday&&rmonth==N1.rmonth&&ryear==N1.ryear)
{
ifstream out("notes2");
out>>str;
cout<<"\n";
cout<<"The note added was:\n";
cout<<str<<"\n";
out.close();
}
else
throw(x);
}catch(int i)
{
cout<<"no notes to display\n";
}
}
};
int main()
{
while(1)
{
calender *ptr1,*ptr2;
MONTH m;
ptr1=&m;
GETDAY g;
ptr2=&g;
NOTE N1,N2;
int value,iyear;
cout<<"\n**********************************";
cout<<"\n1.PRINT A MONTH\n2.CHECK FOR A LEAP YEAR\n3.GET THE DAY\n4.ADD NOTE\n5.VIEW NOTE\n6.EXIT\n"<<endl;
cout<<"\nEnter the operation to be done\n";
cin>>value;
switch(value)
{
case 1:
cout<<"enter the year\n";
cin>>iyear;
m.get_month();
m.leap(iyear);
ptr1->show();
break;
case 2:
LEAP l;
l.get_input();
l.check_leap();
break;
case 3:
g.get_info();
ptr2->show();
break;
case 4: N1.get_date();
N1.get_string();
N1.add();
break;
case 5:
N2.get_date();
N2.get_print(N1);
break;
case 6 : exit(0);
}
}
return 0;
}