home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Uso de la consola / CppDateClass / CppDateClass.cpp next >
Encoding:
C/C++ Source or Header  |  2002-07-15  |  794 b   |  36 lines

  1. //--------------------------------------------
  2. // CppDateClass.cpp ⌐ 2001 by Charles Petzold
  3. //--------------------------------------------
  4. #include <stdio.h>
  5.  
  6. class Date
  7. {
  8. public:
  9.      int year;
  10.      int month;
  11.      int day;
  12.  
  13.      int IsLeapYear()
  14.      {
  15.           return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));
  16.      }
  17.      int DayOfYear()
  18.      {
  19.           static int MonthDays[12] = {   0,  31,  59,  90, 120, 151,
  20.                                        181, 212, 243, 273, 304, 334 };
  21.  
  22.           return MonthDays[month - 1] + day + ((month > 2) && IsLeapYear());
  23.      }
  24. };
  25. int main(void)
  26. {
  27.      Date mydate;
  28.  
  29.     mydate.month = 8;
  30.     mydate.day   = 29;
  31.     mydate.year  = 2001;
  32.  
  33.     printf("Dφa del a±o = %i\n", mydate.DayOfYear());
  34.  
  35.     return 0;
  36. }