// PROGRAM TO FIND THE NEXT DATE OF A GIVEN DATE
#include<iostream.h>
#include<conio.h>
class udate
{
int day, month, year;
public:
void read()
{
cin>>day>>month>>year;
}
void write()
{
cout<<day<<"/"<<month<<"/"<<year;
}
friend int valid(udate);
void operator++();
};
int valid(update D)
{
int d = D.day;
int m = D.month;
int y = D.year;
if(d <= 0|| d>31 || m <= 0 || m>12 || y<=0)
return(0);
else
if(( m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) && d>31)
return(0);
else
if(( m==4 || m==6 || m==9 || m==11) && d>30)
return(0);
else
if( m==2 )
{
if((y%100==0 && y%400==0 && d>29)
|| (y%100==0 && y%400!=0 && d>28))
return(0);
else
if((y%4==0 && d>29) || (y%4!=0 && d>28))
return(0);
}
return(1);
}
void udate :: operator ++()
{
if(month==2)
{
if((y%100==0 && year%400==0 && day==29) || (year%100==0 && year%400!=0 && day==28))
{
day=1;
month ++;
}
else
if(year%4==0 && day==29)||(year%4!=0 && day==28))
{
day=1;
month++;
}
else
day++;
}
else
if((month==1 || month==3 || month ==5 || month==7
|| month==8 || month==10 || month==12) && day==31)
{
day=1;
if(month==12)
{
month = 1;
year++;
}
else
month++;
}
else
{
if((month==4 || month==6 || month==9 || month==11) && day == 30)
{
day=1;
month++;
}
else
day++;
}
}
void main()
{
udate d1;
clrscr();
cout<<" PROGRAM FOR FINDING THE NEXT DATE USING OPERATOR OVERLOADING '++'\n\n";
while(1)
{
cout<<"ENTER THE DATE :";
d1.read();
if(!valid(d1))
cout<<"INVALID DATE PLEASE ENTER THE CORRECT DATE ..."<<endl;
else
break;
}
cout<<endl<<"\n THE GIVEN DATE IS :";
d1.write();
++d1;
cout<<endl<<"\n AFTER INCREMENTING :";
d1.write();
getch();
}
sweety 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.