#include <iostream>
#include "date.h"
using namespace std;
int main()
{
int d, m, y;
cout<<"Enter start date (DD/MM/YYYY): "<<endl;
scanf("%d/%d/%d", &d, &m, &y);
date d1(d,m,y);
cout<<"Enter end date (DD/MM/YYYY): "<<endl;
scanf("%d/%d/%d", &d, &m, &y);
date d2(d,m,y);
cout<<d2-d1;
return 0;
}
#include <string>
class date
{
private:
int day = 0;
int month = 0;
int year = 0;
public:
date(int, int, int);
date();
friend std::string operator - (const date &, const date &);
};
#include <string>
#include "date.h"
using namespace std;
date::date(int d, int m, int y)
{
day = d;
month = m;
year = y;
}
date::date(){}
string operator - (const date &d2, const date &d1)
{
date r;
int tmpDay = d2.day;
r.month = d2.month - d1.month;
r.year = d2.year - d1.year;
if(d2.day < d1.day)
{
switch(d2.month)
{
case 3:
if ((d2.year % 4 == 0 && d2.year % 100 != 0)
|| d2.year % 400 == 0)
tmpDay += 29;
else
tmpDay += 28;
break;
case 5:
case 7:
case 10:
case 12:
tmpDay += 30;
break;
default:
tmpDay += 31;
}
r.month--;
}
r.day = tmpDay - d1.day;
return to_string(r.year)+" years "
+to_string(r.month)+" months "
+to_string(r.day)+" days passed since.\n";
}