#include <iostream>
using namespace std;
class dateType
{
public:
/* Method: Default contructor
* Description: Constructs a new dateType object
* Pre-conditions: None
* Post-conditions: dateType object created and initialized to a date of
* '0000-00-00' (format yyyy-mm-dd)
* Method input: Year (int), Month (int), Day (int)
* Method output: None
*/
dateType();
/* Method: Constructor
* Description: Constructs a new dateType object
* Pre-conditions: None
* Post-conditions: dateType object create and initialized to a date of
* format yyyy-mm-dd
* Method input: year (int), month (int), day (int)
* Method output: None
*/
dateType(int, int, int);
/* Method: setDate
* Description: Sets the date of a dateType object
* Pre-conditions: dateType object has been initialized
* Post-conditions: new year, month and day has been set for dateType
* object
* Method input: year(int), month(int), day(int)
* Method output: None
*/
void setDate(int y, int m, int d);
/* Method: getYear
* Descritpion: Returns the year of the dateType object
* Pre-conditions: dateType object exists
* Post-conditions: dateType object year has been returned
* Method input: None
* Method output: Year of the dateType (int)
*/
int getYear() const;
/* Method: getMonth
* Descritpion: Returns the month of the dateType object
* Pre-conditions: dateType object exists
* Post-conditions: dateType object month has been returned
* Method input: None
* Method output: Month of the dateType object (int)
*/
int getMonth() const;
/* Method: getDay
* Description: Returns the day of the dateType object
* Pre-conditions: dateType object exists
* Post-conditions: dateType object month has been returned
* Method input: None
* Method output: Day of the dateType object (int)
*/
int getDay() const;
/* Method: getDate
* Description: Returns the year, month, and day of the dateType object
* Pre-conditions: dateType object exists
* Post-conditions: dateType object year, month and day has been returned
* Method input: None
* Method output: year (int), month(int), and day(int) of the dateType
* object
*/
dateType getDate() const;
bool operator==(const dateType& otherDate) const;
bool operator!=(const dateType& otherDate) const;
bool operator<(const dateType& otherDate) const;
bool operator>(const dateType& otherDate) const;
bool operator<=(const dateType& otherDate) const;
bool operator>=(const dateType& otherDate) const;
ostream& operator<<(ostream& out);
istream& operator>>(istream& in);
private:
int year;
int month;
int day;
};
void dateType::setDate(int y, int m, int d)
{
year = y;
month = m;
day = d;
}
int dateType::getYear() const
{
return year;
}
int dateType::getMonth() const
{
return month;
}
int dateType::getDay() const
{
return day;
}
dateType dateType::getDate() const
{
return dateType(year, month, day);
}
bool dateType::operator==(const dateType& otherDate) const
{
return (getYear() == otherDate.getYear() && getMonth() == otherDate.getMonth()
&& getDay() == otherDate.getDay());
}
bool dateType::operator!=(const dateType& otherDate) const
{
return !(*this == otherDate);
}
bool dateType::operator<(const dateType& otherDate) const
{
return (getYear() < otherDate.getYear() || getMonth() < otherDate.getMonth()
|| getDay() < otherDate.getDay());
}
bool dateType::operator>(const dateType& otherDate) const
{
return (getYear() > otherDate.getYear() || getMonth() > otherDate.getMonth()
|| getDay() > otherDate.getDay());
}
bool dateType::operator<=(const dateType& otherDate) const
{
return *this == otherDate || *this < otherDate;
}
bool dateType::operator>=(const dateType& otherDate) const
{
return *this == otherDate || *this > otherDate;
}
ostream& dateType::operator<<(ostream& out)
{
out << this->getYear() << "-" << this->getMonth() << "-" << this->getDay();
return out;
}
istream& dateType::operator>>(istream& in)
{
//Variables
int year,
month,
day;
char dummy;
in >> year >> dummy >> month >> dummy >> day;
this->setDate(year, month, day);
return in;
}
dateType::dateType()
{
year = 0000;
month = 00;
day = 00;
}
dateType::dateType(int y, int m, int d)
{
setDate(y, m, d);
}
int main(){
dateType first_date(2014, 10, 31);
}