//using operator overloading find difference between two date. enter a latest date first.
#include "iostream"
using namespace std;
class date
{
int day;
int month;
int year;
public:
void input()
{
int d,m,y;
cout "enter date(dd mm yyyy)"; cin>>d>>m>>y;
day=d;
month=m;
year=y;
}
void show()
{cout date month & year
}
date operator -(date);
};
date date::operator -(date di)
{
date t;
t.year=year-di.year;
t.month=month-di.month;
t.day=day-di.day;
if((t.year)<0)
cout "first date should be greater" endl; if((t.month)<0){
t.year=t.year-1;
t.month=t.month+12;}
if(t.day<0){
t.month=t.month-1;
t.day=t.day+30;}
return t;
}
int main()
{
date d1;
d1.input();
date d2;
d2.input();
date d3;
d3=d1-d2;
cout "difference of date is :" endl;
d3.show();
system("pause");
return 0;
}
No comments:
Post a Comment