/*************************************************************************** Program: A2Q2.cpp Purpose: Program to overload operators using a Date class. A menu is added to test the functions. ****************************************************************************/ #include #include using namespace std; bool testdate(int yeara, int montha, int daya); class date { public: date (int newday, int newmonth); date (int newday, int newmonth, int newyear); // int nextdate (); int getday() const; int getmonth() const; int getyear() const; void setday(int newday1); void setmonth(int newmonth1); void setyear(int newyear1); //bool testdate(int datetest); private: int day; int month; int year; }; date::date (int newday, int newmonth) // constructor without year :day(newday), month(newmonth),year(2004) { if ((testdate(2004,newmonth,newday))==0){ cout<<" ERROR invalid date"<(const date& date1, const date& date2) { if (date1.getyear() > date2.getyear()){ return 1; }; if (date1.getyear()==date2.getyear()){ if(date1.getmonth() > date2.getmonth()){ return 1; }; if(date1.getday()> date2.getday()){ return 1; }; }; return 0; }; bool operator >=(const date& date1, const date& date2) { return ((date1>date2) || (date1 == date2)); }; ostream& operator <<(ostream& outputstream, const date& date1) { cout<daysinmonth){ date2.setday(date2.getday()-daysinmonth); date2.setmonth(date2.getmonth()+1); if (date2.getmonth()> 12) { date2.setmonth(1); date2.setyear(date2.getyear()+1); }; }; return date2; }; istream& operator >>(istream& inputstream, date& date1) { int correct=0; while (correct==0){ correct=1; int tempyear=1; int temp; cout<> temp; date1.setyear(temp); cout << "Enter month : "; cin >> temp; date1.setmonth(temp); cout << "Enter day : "; cin >> temp; date1.setday(temp); if ((testdate(date1.getyear(),date1.getmonth(),date1.getday()))==0){ cout<364) { date1.setyear(date1.getyear()+1); a=a-365; }; int flag=1; while (flag==1) { if ((date1.getmonth()==1) || (date1.getmonth()==3) || (date1.getmonth()==5)||//check 31 day months (date1.getmonth()==7) || (date1.getmonth()==8)||(date1.getmonth()==10)|| (date1.getmonth()==12)){ date1=addate(a,31,date1);// add 'a' to 31 day months a=0; if (date1.getday()<31){ flag=0; }; }; if ((date1.getmonth()==4) || (date1.getmonth()==6) || (date1.getmonth()==9)||//check 30 day months (date1.getmonth()==11)){ date1=addate(a,30,date1);// add 'a' to 30 day months a=0; if (date1.getday()<30){ flag=0; }; }; if (date1.getmonth()==2){ // february leapcheck=(date1.getyear()); if (((leapcheck/4)-(ceil(leapcheck/4)))==0){ // check for leap year leapset=29; }; date1=addate(a,leapset,date1);// add 'a' to february month leapset=28;// reset back to 28 days a=0; if (date1.getday()12)){ return 0; } if ((testmonth==1) || (testmonth==3) || (testmonth==5)||// 31 day months (testmonth==7) || (testmonth==8)||(testmonth==10)|| (testmonth==12)){ if ((testday<=0)||(testday>31)){ return 0; }; return 1; }; if ((testmonth==4) || (testmonth==6)||// 30 day months (testmonth==9) || (testmonth==11)){ if ((testday<=0)||(testday>30)){ return 0; }; return 1; }; if ((testmonth==2)){ if (((leapcheck/4)-(ceil(leapcheck/4)))==0){ // check for leap year leapset=29; }; if ((testday<=0)|| (testday>leapset)){ return 0; }; return 1; }; return 1; }; int main () { // Input two dates, Date1 and Date 2/// date somedate1(1,1);// test initialisation of only day and month, year defaults to 2004 date somedate2(1,1,1); date olddate(1,1,1); int dayadd=100; cout<< "This program performs several operator functions on two dates of the year"<>somedate1;// test overload function >> cout<>somedate2; cout< 0) && (select <8)) { cout< Date 2"<= Date 2"<> select; switch (select) { case 1:// Check if Date 1 < Date 2 cout<<"The satement "< Date 2 cout<<"The satement "< "< somedate2){ cout<<" is TRUE"<= Date 2 cout<<"The satement "<= "<= somedate2){ cout<<" is TRUE"<>dayadd; olddate=somedate1; somedate2=somedate1+dayadd; somedate1=olddate; cout<<"Date1 =: "<