Code:class Date
{ //data
public:
Date(int =1,int=1,int=1900);//default constructor
Date &setDate(int,int,int);
Date &setMonth(int); //set month
Date &setDay(int); //set day
Date &setYear(int); //set year
int getMonth() const;
int getDay() const;
int getYear() const;
void print() const;
protected:
int month;
int day;
int year;
//data
};
///////////////////////////////////////////////////////////////////////////
// Date constructor with range checking
Date::Date(int m, int d, int y)
{
month= (m > 0 && m<=12)? m:1;
day=(d>=1 && y<=31)?y:1;
year=(y>=1900 && y <2500)? y:1900;
}
Date &Date::setDate(int m,int d,int y)
{
month= (m > 0 && m<=12)? m:1;
day=(d>=1 && d<=31)?d:1;
year=(y>=1900 && y <2500)? y: 1900;
return *this;
}
//Set function
Date &Date::setMonth(int m)
{
month=(m > 0 && m<=12)? m:1;
return *this; //enables chaining
}
Date &Date::setDay(int d)
{
day=(d>=1 && d<=31)?d:1;
return *this; //enables chaining
}
Date &Date::setYear(int y)
{
year=(y>=1900 && y <2500)? y: 1900;
return *this; //enables chaining
}
//Get function
int Date::getMonth() const
{ return month; }
int Date::getDay() const
{ return day;}
int Date::getYear() const
{ return year;}
//Display print function
void Date::print() const
{
cout<<month<<" "<< day<<" " << year<<"\n";
}
//Just give me brief explaination and ideas.. to do.these .Thanks
//A method that takes two dates as arguments
//and return true(or 1)provided the first date
//occurs before the second date else return false(or 0)
//class earlier:public Date
//just tell me what should i do ?
//do i need to get user keyin for two dates?
//A method Christmas which given a date, should return
//the number of days until the next Christmas day(December,25)
//class christmas:public Date
//just tell me what should i do?
//Given two date,return no. of days between the given two dates.
//For e.g. daysBetween(Date(12,4,1970),Date(22,4,1970) is 10.
//The program should cope with dates having different months.
//class Compare:public Date
//just tell me what should i do...?
//////////////////////////////////////////////////////////////////
main()
{
Date d1;
d1.setMonth(07).setDay(27).setYear(1982);
cout<<"Henry Birthday: ";
d1.print();
return 0;
}
Please use [code][/code]Tags