/*
Definition : Construct a class Calendar with data members as date, month
and year. Implement constructors, overloaded constructors and destructors
for the same. Write down overloaded operator ++ that will increment the
date by one and print new date, month and year.
e.g. if date is 31/7/2005 then output : tomorrow is 1/8/2005
Tutorial Date :
Lab Date :
*/
#include<iostream.h>
#include<conio.h>
class Calendar
{
int dd,mm,yy;
public:
Calendar()
{
dd=0;
mm=0;
yy=0;
}
Calendar(int d,int m,int y)
{
dd=d;
mm=m;
yy=y;
}
void operator ++()
{
dd++;
if(dd>31)
{
mm++;
dd=1;
}
if(mm>12)
{
yy++;
mm=1;
}
cout<<dd<<"/"<<mm<<"/"<<yy;
}
~Calendar()
{
dd=NULL;
mm=NULL;
yy=NULL;
}
};
int main()
{
int d,m,y;
clrscr();
Calendar c;
cout<<"Enter date:";
cin>>d;
cout<<"Enter month:";
cin>>m;
cout<<"Enter year:";
cin>>y;
c=Calendar(d,m,y);
c.operator++();//c++;
getch();
return 0;
}
No comments:
Post a Comment