Public paste
object file
By: j00s | Date: Sep 20 2007 02:26 | Format: C++ | Expires: never | Size: 993 B | Hits: 761

  1. // functions
  2.  
  3.  
  4.  
  5. #include <iostream>
  6. #include "Date.h"
  7.  
  8.  
  9. const int Date::days[] =
  10. { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  11.  
  12.  
  13. //constructor
  14.  
  15. Date::Date ( int m, int d, int y )
  16.  
  17. {
  18.  
  19. setDate ( m, d, y );
  20. }
  21.  
  22.  
  23. void Date::setDate( int mm, int dd, int yy )
  24. {
  25.  
  26. month = ( mm >= 1 && mm <= 12 ) ? mm : 1;
  27. year = ( yy >= 1900 && yy <= 2100 ) ? yy : 1900;
  28.  
  29. }
  30.  
  31.  
  32. Date &Date::operator++()
  33. {
  34.  
  35. helpIncrement();
  36.  
  37. return *this;
  38. }
  39.  
  40. Date Date::operator++( int )
  41.  
  42. {
  43.  
  44. Date temp = *this;
  45. helpIncrement();
  46.  
  47. return temp;
  48. }
  49.  
  50.  
  51. const Date &Date::operator+=( int additionalDays)
  52. {
  53. for (int i=0; i < additionalDays; i++ )
  54. helpIncrement();
  55.  
  56. return *this;
  57. }
  58.  
  59.  
  60.  
  61. void Date::helpIncrement()
  62. {
  63.  
  64.  
  65. if (month < 12 )
  66. {
  67. month++;
  68. day = 1;
  69. }
  70. else
  71. {
  72. year++;
  73. month=1;
  74. day=1;
  75. }
  76. }
  77. ostream &operator<<( ostream &output, const Date &d)
  78.  
  79. {
  80.        
  81.         output << d.month << " " << d.day << " " << d.year;
  82.         return output;
  83.  
  84.  
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
Latest pastes
6 hours ago
6 days ago
18 days ago
23 days ago
25 days ago