C++: Day of the Week

Bjarne-stroustrup
 

A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January).

In what years between 2008 and 2121 will the 25th of December be a Sunday?

Using any standard date handling libraries of your programming language; compare the dates calculated with the output of other languages to discover any anomalies in the handling of dates which may be due to, for example, overflow in types used to represent dates/times similar to y2k type problems.

#include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>

int main( ) {
	using namespace boost::gregorian ;

	std::cout
	<< "Yuletide holidays must be allowed in the following years:\n" ;
	for ( int i = 2008 ; i < 2121 ; i++ ) {
		greg_year gy = i ;
		date d  ( gy, Dec , 25 ) ;
		if ( d.day_of_week( ) == Sunday ) {
			std::cout << i << std::endl ;
		}
	}
	std::cout << "\n" ;
	return 0 ;
}
Output:
Yuletide holidays must be allowed in the following years:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118

SOURCE

Content is available under GNU Free Documentation License 1.2.