#include<iostream.h> #include<conio.h> //------------------------------ day ----------------------------------// class day { private: int date; int month; int year; public: day() { date=0; month=0; year=0; } void get_date(); void show_days(day,day); void show_date(); int next_month(int,int); int next_year(int); int operator>(day); }; //--------------------------- get_date( ) -----------------------------// void day::get_date() { cout<<\"\\tEnter the date = \"; cin>>date; cout<<\"\\tEnter the month = \"; cin>>month; cout<<\"\\tEnter the year = \"; cin>>year; } //-------------------------- show_date( ) -----------------------------// void day::show_date() { cout<<\"\\n\\t Date is \"; cout<<((date<10)?\"0\":\"\")<<this->date<<\" : \"; cout<<((month<10)?\"0\":\"\")<<this->month<<\" : \"<<this->year<<endl; } //--------------------------- show_days(day,day) ----------------------// void day::show_days(day d1,day d2) { long d=0; if(d2.date<d1.date && d2.month!=d1.month && d2.year>=d1.year) { d2.date+=next_month(d2.month-1,d2.year); d2.month--; } for(int count_1=d1.date;count_1<d2.date;count_1++) d++; if(d2.month<d1.month && d2.year>d1.year) { d2.month+=12; d2.year--; } for(int count_2=d1.month;count_2<d2.month;count_2++) d+=next_month(count_2,d1.year); for(int count_3=d1.year;count_3<d2.year;count_3++) d+=365+next_year(count_3); cout<<\"\\t Number of days b/w date1 & date2 = \"<<d<<\" days\"<<endl; } //--------------------------- operator>(day) --------------------------// int day::operator>(day d) { long d1; long d2; d2=date+(month*30)+(year*360); d1=d.date+(d.month*30)+(d.year*360); return (d2>d1?1:0); } //------------------------- next_month(int,int) -----------------------// int day::next_month(int m,int y) { int d; if(m<1) m+=12; else if(m>12) m-=12; switch(m) { case 1 : d=31; break; case 2 : d=28+next_year(y); break; case 3 : d=31; break; case 4 : d=30; break; case 5 : d=31; break; case 6 : d=30; break; case 7 : d=31; break; case 8 : d=31; break; case 9 : d=30; break; case 10 : d=31; break; case 11 : d=30; break; case 12 : d=31; break; } return d; } //--------------------------- next_year(int) --------------------------// int day::next_year(int y) { if(y%4==0 || y%4==0 || y%100==0) return 1; else return 0; } //----------------------------- Main( ) -------------------------------// main() { clrscr(); day date_1; day date_2; day date_3; cout<<\"\\n Enter the date in the pattern i.e dd/mm/yy \"<<endl; cout<<\"\\n First Date :\"<<endl; date_1.get_date(); cout<<\"\\n Second Date :\"<<endl; date_2.get_date(); cout<<\"\\n********** First Date **********\"<<endl; date_1.show_date(); cout<<\"\\n********** Second Date **********\"<<endl; date_2.show_date(); cout<<\"\\n********** Result **********\\n\"<<endl; if(date_1>date_2) date_3.show_days(date_2,date_1); else date_3.show_days(date_1,date_2); getch(); return 0; }