Please Help me with this Date Operation Program. I think that this works....yet!
Thanks
#include <iostream.h>
#include <conio.h>
int a[7]={1,3,5,7,8,10,12};
int b[7]={4,6,9,11};
class manipdate
{
int date;
int month;
int year;
public:
int d,m,y;
void getdata()
{
cout<<"\n\n Date : ";
cin>>date;
cout<<"\n Month : ";
cin>>month;
cout<<"\n Year : ";
cin>>year;
}
void display(int d, int m, int y)
{
cout<<" "<<d<<" / "<<m<<" / "<<y;
}
manipdate sub(manipdate q)
{
if(q.d < 0)
{
q.d = -q.d;
if(q.d>30)
{
for(int i=0;i<7;i++)
{
if(q.m==a[i])
{
if(q.d>31)
{
q.d -= 31;
q.m--;
}
}
else if(q.m==b[i])
{
q.d -= 30;
q.m++;
}
}
}
}
if(q.m < 0)
{
q.m = -q.m;
while(q.m > 12)
{
q.m -= 12;
q.y--;
}
}
return q;
}
manipdate operator +(manipdate &x)
{
manipdate q;
q.d=date+x.date;
q.m=month+x.month;
q.y=year+x.year;
while(q.m>12)
{
q.m -= 12;
q.y++;
}
if(q.m == 2)
{
if(q.y%4==0)
{
if(q.d>29)
q.d -= 29;
}
}
if(q.d>30)
{
for(int i=0;i<7;i++)
{
if(q.m==a[i])
{
if(q.d>31)
{
q.d-=31;
q.m++;
}
}
else if(q.m==b[i])
{
q.d-=30;
q.m++;
}
}
}
while(q.m>12)
{
q.m-=12;
q.y++;
}
display(q.d,q.m,q.y);
return (q);
}
manipdate operator -(manipdate &x)
{
manipdate q;
if(year > x.year)
{
q.y = year - x.year;
q.m = month - x.month;
q.d = date - x.date;
q=sub(q);
}
else if(x.year > year)
{
q.y = x.year - year;
q.m = x.month - month;
q.d = x.date - date;
q=sub(q);
}
else if(x.year = year)
{
q.y = 0;
if(month > x.month)
{
q.m = month - x.month;
q.d = date - x.date;
q=sub(q);
}
else if(month < x.month)
{
q.m = x.month - month;
q.d = x.date - date;
q=sub(q);
}
else
{
q.y = 0;
q.m = 0;
if(date > x.date)
{
q.d = date - x.date;
q=sub(q);
}
else if(date < x.date)
{
q.d = x.date - date;
q=sub(q);
}
else
{
q.d = 0;
q=sub(q);
}
}
}
display(q.d,q.m,q.y);
return q;
}
};
void main()
{
clrscr();
manipdate d1,d2;
cout<<"\n Enter the Date\n";
d1.getdata();
cout<<"\n Enter the Date\n";
d2.getdata();
cout<<"\n\n The Addition of the Dates : \n\n";
d1+d2;
cout<<"\n\n The Subtraction of the Dates : \n\n";
d1-d2;
getch();
}