... ++month; // increment month
94            day = 1; // first day of new month
95          }
96          else { // last day of year
97             ++year; // increment year
98             month = 1; // first month of new year
99             day = 1; // first day of new month
100         }
101      }
102   }
103
104   // overloaded output operator
105   ostream& operator<<(ostream& output, const Date& d) {
106      static string monthName[13]{"", "January", "February",
107         "March", "April", "May", "June", "July", "August",
108         "September", "October", "November", "December"};
109      output << monthName[d.month] << ' ' << d.day << ", " << d.year;
110      return output; // enables cascading
111   }

Fig. 10.8 Date class test program.

Alternate View ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.