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
|
#include<iostream.h>
#include<conio.h>
int maxdays(int m)
{
int dmax;
switch(m)
{
case 1:{dmax=31;break;}
case 2:{dmax=28;break;}
case 3:{dmax=31;break;}
case 4:{dmax=30;break;}
case 5:{dmax=31;break;}
case 6:{dmax=30;break;}
case 7:{dmax=31;break;}
case 8:{dmax=31;break;}
case 9:{dmax=30;break;}
case 10:{dmax=31;break;}
case 11:{dmax=30;break;}
case 12:{dmax=31;break;}
}
return dmax;
}
class Date
{
private:
int day,month;
public:
int dayscalc(Date dt)
{
int d,m,t,count=0;
d=dt.day;
m=dt.month;
for(int i=1;i<=m;i++)
{
if(i==m)
t=d;
else
t=maxdays(m);
for(int i=1;i<=t;i++)
{
count++;
}
}
return count;
}
void getDate()
{
cout<<"\nEnter Day (numeric):";
cin>>day;
cout<<"\nEnter Month (numeric):";
cin>>month;
}
void showDate()
{
cout<<"\nThe Day is:"<<day<<" and the month is:"<<month;
}
void addDate(Date d1, Date d2)
{
int a=dayscalc(d1),b=dayscalc(d2),c=a+b,d,e,flag=0;
int dys=1,mts=1;
if(c>365)
{
c-=365;
cout<<"\nNew Year";
}
for(int i=1;i<=c;i++)
{
e=0,d=0;
for(int j=1;j<=12;j++)
{
if (flag==1)
break;
e=maxdays(j);
d+=e;
if(i>d)
mts++;
else if((i==c)&&(d==i))
{
d-=e;
dys=c-d;
flag=1;
day=dys;
month=mts;
break;
}
}
}
}
};
void main()
{
clrscr();
Date D1,D2,D3;
D1.getDate();
D2.getDate();
D3.addDate(D1,D2);
D3.showDate();
getch();
}
|