#include<iostream.h>
class date
{
public:
int d,m,y,n1,n2;
void getDate(); //get the date
void putDate(); //print the result
void addDate(); //add the date
void subDate(); //sub the date
void swapDate(); // swap the date
void diffDate(); //diff the date
void dayDate(); // find the day
};
date ven,d1,d2,d3,t,g;// create object
void date::swapDate() //Swap the bigger date
{
if ((d1.y<d2.y)||((d1.y==d2.y)&&(d1.m<d2.m))||((d1.y==d2.y)&&(d1.m==d2.m)&&(d1.d<d2.d)))
{
t=d1;
d1=d2;
d2=t;
}
}
void date::getDate()
{
cout<<"Enter the year:"<<endl;
cin>>y;
cout<<"Enter the month:"<<endl;
a:
cin>>m;
if(m>12)
{
cout<<"Enter the correct month:"<<endl; //check the month
goto a;
}
cout<<"Enter the date:"<<endl;
b:
cin>>d;
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12) //check the date
{
if(d>31)
{
cout<<"Enter the correct date:"<<endl;
goto b;
}
}
else if(m==4||m==6||m==9||m==11)
{
if(d>30)
{
cout<<"Enter the correct date:"<<endl;
goto b;
}
}
else if(m==2)
{
if((y%4)==0)
{
if(d>29)
{
cout<<"Enter the correct date:"<<endl;
goto b;
}
}
else
{
if(d>28)
{
cout<<"Enter the correct date:"<<endl;
goto b;
}
}
}
}
void date::putDate()
{
cout<<"------------------"<<endl;
cout<<"Date==>"<<d<<":"<<m<<":"<<y<<endl;
cout<<"------------------"<<endl;
}
void date::addDate()
{
int f=0;
cout<<"Enter the Number to add the date:"<<endl;
cin>>n1;
d=d+n1;
while(f==0)
{
if((m==1||m==3||m==5||m==7||m==8||m==10||m==12)&&(f==0))
{
if(d>31)
{
d=d-31;
m++;
if(m>12)
{
y=y+1;
m=m-12;
}
}
else
f=1;
}
else if((m==4||m==6||m==9||m==11)&&(f==0))
{
if(d>30)
{
d=d-30;
m++;
}
else
f=1;
}
else
{
if(m==2&&f==0)
{
if((y%4)==0)
{
if(d>29)
{
d=d-29;
m++;
}
else
f=1;
}
else
{
if(d>28)
{
d=d-28;
m++;
}
else
f=1;
}
}
}
}
}
void date::subDate() // subtract the date
{
int f=0;
cout<<"Enter the number to sub the date:"<<endl;
cin>>n2;
d=d-n2;
while(f==0)
{
if((m==5||m==7||m==10||m==12)&&(f==0))
{
if(d<1)
{
d=d+30;
m--;
}
else
f=1;
}
else if ((m==1||m==2||m==4||m==6||m==8||m==9||m==11)&&(f==0))
{
if(d<1)
{
d=d+31;
m--;
if(m==0)
{
m=m+12;
y=y-1;
}
}
else
f=1;
}
else
{
if((m==3)&&(f==0))
{
if((y%4)==0)
{
if(d<1)
{
d=d+29;
m--;
}
else
f=1;
}
else
{
if(d<1)
{
d=d+28;
m--;
}
else
f=1;
}
}
}
}
}
int dayd;
void date::diffDate() // fint the difference of the two date
{
int f=0,count=0;
dayd=0;
while(f==0)
{
a:
if((d1.y==d2.y)&&(d1.m==d2.m)&&(d1.d==d2.d)&&(f==0))
{
dayd=count;
f=1;
}
d2.d++;
count++;
if(((d2.m==4)||(d2.m==6)||(d2.m==9)||(d2.m==11))&&(f==0))
{
if(d2.d>30)
{
d2.d=1;
d2.m++;
}
else
goto a;
}
else if (((d2.m==1)||(d2.m==3)||(d2.m==5)||(d2.m==7)||(d2.m==8)||(d2.m==10)||(d2.m==12))&&(f==0))
{
if(d2.d>31)
{
d2.d=1;
d2.m++;
if(d2.m>12)
{
d2.m=1;
d2.y++;
}
}
else
goto a;
}
else
{
if((d2.m==2)&&(f==0))
{
if((d2.y%4)==0)
{
if(d2.d>29)
{
d2.d=1;
d2.m++;
}
else
goto a;
}
else
{
if(d2.d>28)
{
d2.d=1;
d2.m++;
}
else
goto a;
}
}
}
}
}
void date::dayDate()
{
int temp;
cout<<" The day is ";
temp=dayd;
temp=temp%7;
switch(temp)
{
case 0:
cout<<"Friday";
break;
case 1:
cout<<"Saturday";
break;
case 2:
cout<<"Sunday";
break;
case 3:
cout<<"Monday";
break;
case 4:
cout<<"Tuesday";
break;
case 5:
cout<<"Wednesday";
break;
case 6:
cout<<"Thursday";
break;
}
}
void main()
{
int o;
char ch='y';
while(ch=='y')
{
cout<<"select any one:"<<endl;
cout<<endl<<"1:add"<<endl<<"2:sub"<<endl<<"3.difference"<<endl<<"4.find the day"<<endl;
cin>>o;
switch(o)
{
case 1:
ven.getDate();
ven.putDate();
ven.addDate();
ven.putDate();
break;
case 2:
ven.getDate();
ven.putDate();
ven.subDate();
ven.putDate();
break;
case 3:
d1.getDate();
d2.getDate();
d1.putDate();
d2.putDate();
d3.swapDate();
g.diffDate();
cout<<"The date difference is:"<<dayd<<endl;
break;
case 4:
d1.getDate();
d2.d=15;
d2.y=1947;
d2.m=8;
d1.putDate();
d3.swapDate();
g.diffDate();
g.dayDate();
break;
}
cout<<endl<<"if you want to continue:"<<endl;
cin>>ch;
if(ch=='n')
{
cout<<" "<<endl;
cout<<"===============OK..............BYE==============="<<endl;
}
}
}