fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class dateType
  6. {
  7. public:
  8. /* Method: Default contructor
  9.   * Description: Constructs a new dateType object
  10.   * Pre-conditions: None
  11.   * Post-conditions: dateType object created and initialized to a date of
  12.   * '0000-00-00' (format yyyy-mm-dd)
  13.   * Method input: Year (int), Month (int), Day (int)
  14.   * Method output: None
  15.   */
  16. dateType();
  17.  
  18. /* Method: Constructor
  19.   * Description: Constructs a new dateType object
  20.   * Pre-conditions: None
  21.   * Post-conditions: dateType object create and initialized to a date of
  22.   * format yyyy-mm-dd
  23.   * Method input: year (int), month (int), day (int)
  24.   * Method output: None
  25.   */
  26. dateType(int, int, int);
  27.  
  28. /* Method: setDate
  29.   * Description: Sets the date of a dateType object
  30.   * Pre-conditions: dateType object has been initialized
  31.   * Post-conditions: new year, month and day has been set for dateType
  32.   * object
  33.   * Method input: year(int), month(int), day(int)
  34.   * Method output: None
  35.   */
  36. void setDate(int y, int m, int d);
  37.  
  38. /* Method: getYear
  39.   * Descritpion: Returns the year of the dateType object
  40.   * Pre-conditions: dateType object exists
  41.   * Post-conditions: dateType object year has been returned
  42.   * Method input: None
  43.   * Method output: Year of the dateType (int)
  44.   */
  45. int getYear() const;
  46.  
  47. /* Method: getMonth
  48.   * Descritpion: Returns the month of the dateType object
  49.   * Pre-conditions: dateType object exists
  50.   * Post-conditions: dateType object month has been returned
  51.   * Method input: None
  52.   * Method output: Month of the dateType object (int)
  53.   */
  54. int getMonth() const;
  55.  
  56. /* Method: getDay
  57.   * Description: Returns the day of the dateType object
  58.   * Pre-conditions: dateType object exists
  59.   * Post-conditions: dateType object month has been returned
  60.   * Method input: None
  61.   * Method output: Day of the dateType object (int)
  62.   */
  63. int getDay() const;
  64.  
  65. /* Method: getDate
  66.   * Description: Returns the year, month, and day of the dateType object
  67.   * Pre-conditions: dateType object exists
  68.   * Post-conditions: dateType object year, month and day has been returned
  69.   * Method input: None
  70.   * Method output: year (int), month(int), and day(int) of the dateType
  71.   * object
  72.   */
  73. dateType getDate() const;
  74. bool operator==(const dateType& otherDate) const;
  75. bool operator!=(const dateType& otherDate) const;
  76. bool operator<(const dateType& otherDate) const;
  77. bool operator>(const dateType& otherDate) const;
  78. bool operator<=(const dateType& otherDate) const;
  79. bool operator>=(const dateType& otherDate) const;
  80. ostream& operator<<(ostream& out);
  81. istream& operator>>(istream& in);
  82.  
  83. private:
  84. int year;
  85. int month;
  86. int day;
  87. };
  88.  
  89. void dateType::setDate(int y, int m, int d)
  90. {
  91. year = y;
  92. month = m;
  93. day = d;
  94. }
  95.  
  96. int dateType::getYear() const
  97. {
  98. return year;
  99. }
  100.  
  101. int dateType::getMonth() const
  102. {
  103. return month;
  104. }
  105.  
  106. int dateType::getDay() const
  107. {
  108. return day;
  109. }
  110.  
  111. dateType dateType::getDate() const
  112. {
  113. return dateType(year, month, day);
  114. }
  115.  
  116. bool dateType::operator==(const dateType& otherDate) const
  117. {
  118. return (getYear() == otherDate.getYear() && getMonth() == otherDate.getMonth()
  119. && getDay() == otherDate.getDay());
  120. }
  121.  
  122. bool dateType::operator!=(const dateType& otherDate) const
  123. {
  124. return !(*this == otherDate);
  125. }
  126.  
  127. bool dateType::operator<(const dateType& otherDate) const
  128. {
  129. return (getYear() < otherDate.getYear() || getMonth() < otherDate.getMonth()
  130. || getDay() < otherDate.getDay());
  131. }
  132.  
  133. bool dateType::operator>(const dateType& otherDate) const
  134. {
  135. return (getYear() > otherDate.getYear() || getMonth() > otherDate.getMonth()
  136. || getDay() > otherDate.getDay());
  137. }
  138.  
  139. bool dateType::operator<=(const dateType& otherDate) const
  140. {
  141. return *this == otherDate || *this < otherDate;
  142. }
  143.  
  144. bool dateType::operator>=(const dateType& otherDate) const
  145. {
  146. return *this == otherDate || *this > otherDate;
  147. }
  148.  
  149. ostream& dateType::operator<<(ostream& out)
  150. {
  151. out << this->getYear() << "-" << this->getMonth() << "-" << this->getDay();
  152. return out;
  153. }
  154.  
  155. istream& dateType::operator>>(istream& in)
  156. {
  157. //Variables
  158. int year,
  159. month,
  160. day;
  161. char dummy;
  162.  
  163. in >> year >> dummy >> month >> dummy >> day;
  164. this->setDate(year, month, day);
  165. return in;
  166. }
  167.  
  168. dateType::dateType()
  169. {
  170. year = 0000;
  171. month = 00;
  172. day = 00;
  173. }
  174.  
  175. dateType::dateType(int y, int m, int d)
  176. {
  177. setDate(y, m, d);
  178. }
  179.  
  180. int main(){
  181. dateType first_date(2014, 10, 31);
  182. }
Success #stdin #stdout 0s 3336KB
stdin
Standard input is empty
stdout
Standard output is empty