//
//
//  dates.cc
//
//     Student: Russell Lowke
//         T.F: Francis Crick
//  CSCIE-s111: Unit Five, Easy Supp - question 5 [worth 3pts],  7/17/2002
//

#include <iostream>
#include <iomanip>
#include <cstdlib>

class Date
{
  private:
  			int month, day, year;
     
			bool  leapYear (int y)
			{
				return ((( y % 4 ==0) && (y % 100 ) != 0)
						||  ((y % 400 ) == 0 )  )  ;
			}
 
			int lastPossibleDayofMonth (int m, int y)
			{
				switch ( m )
				{ 
					case 9:  case 4: case 6: case 11: return 30;
					case 2:
						if ( leapYear( y ) ) {
							return 29;
						} else { 
							return 28;
						}
					default:  return 31;
                }
			} 
 			
			bool validDate(int m, int d, int y)
			{
				return ( ( y >= 1) && (m <= 12) && (m >= 1) && (d > 0) &&
						(  d  <= lastPossibleDayofMonth (m, y) )) ;
			}
 
            int daysInYear(int y)
 			{
 				return ( 337 + lastPossibleDayofMonth (2, y) );
 			}
 			
 			int convToDays()
 			{
 				int totDays = 0;
 				
 				for( int i = 1; i < year; i++ ) {
 					totDays += daysInYear(i);
 				}
 				
 				for( int i = 1; i < month; i++ ) {
 					totDays += lastPossibleDayofMonth(i, year);
 				}
 				totDays += day;
 				
 				return totDays;
 			}
 			
  public:	Date ( int m=1, int d=1, int y=1)
			{ 
				if (validDate (m, d, y) )
					{month = m;  day = d;  year =y; }
				else {month = 1; day = 1; year = 1; }
			}
			
 			    
			void readDate ()
			{
				int m, d, y;  char ch;
   
				do {  
					cout << "Input date in form mm/dd/yyyy :  ";
					cin >> m >> ch >> d>> ch>>  y ;
					cin.ignore(80,'\n');
				} while  ( ! validDate (m, d, y) );   
				month = m;  day = d;  year = y;
			} 

			void operator++ ()		// prefix version of ++
			{   if  ( day != lastPossibleDayofMonth(month, year)) {
					day++;
				} else {
					day=1;  month=(month%12)+1; 
            		if ( month == 1 ) {
            			year++;
            		}
				}
			} 
         
			void operator++ (int i)    // postfix version of ++
			{
				if ( day != lastPossibleDayofMonth(month, year) ) {
					day++;
				} else {
					day=1;  
					month=(month%12)+1; 
           			if  (month==1) {
           				year++;
           			}
				}
			} 

			friend ostream& operator<< (ostream& os, Date d)
			{ 
				os << d.month << "/" << d.day << "/" << d.year;
				return os;
			}
			
			//
			// number of days between two dates
			friend int operator- (Date d1,  Date d2)
			{
				int r = d1.convToDays() - d2.convToDays();
				
				return ( abs(r) + 1 );
			}

};


istream& operator>> (istream& is, Date& d)
{
	d.readDate();
	return is;
}
     

Date operator+ (Date d,  int increment)
{
	for (int i = 1; i <= increment; i++) {
		++d;
	}
	return d;
}


void main()
{
	Date d1, d2;
     	
	cin >> d1;
	cin >> d2;
	
	cout << "number of days between: " << d1 - d2 << endl;
	
}