[Exercise 8]

Extent the class "Date"

description | solution | discussion
exercises after lesson "More on Classes"
list of all exercises

Extent class Date with further member functions

a)to compute the weekday (monday=0, tuesday=1, ...., sunday=6)
b)operator+=(long) and operator-=(long), which add/substract the specified number of days to the given date
c)the same for operator+(long) and operator-(long) which do not change the date object but return a new date
d)previous(long weekday): compute the date of the specified previous weekday, e.g. "last wednesday before date" would be date.previous(2)

Then implement a program which prints all offical German holidays for a specified year given the following rules:

"Neujahr" at 1/1
"Hl.3 Könige" at 1/6
"Sommerzeit" last sunday imn March
"Rosenmontag" Easter minus 48 days
"Aschermittwoch"   Easter minus 46 days
"Karfreitag" Easter minus 2 days
"Ostern" Easter (2 days)
"Himmelfahrt" Easter plus 39 days
"Pfingsten" Easter plus 49 days (2 days)
"Fronleichnam" Easter plus 60 days
"Tag der Arbeit" at 5/1
"Muttertag" second sunday in may
"Dt. Einheit" at 10/3
"Winterzeit" last sunday in october
"Allerheiligen" at 11/1
"Buss&Bettag" sunday before 12/25 minus 32 days
"1. Advent" sunday before 12/25 minus 21 days
"2. Advent" sunday before 12/25 minus 14 days
"3. Advent" sunday before 12/25 minus 7 days
"4. Advent" sunday before 12/25
"Hl. Abend" at 12/24
"Weihnachten" at 12/25 (2 days)
"Silvester" at 12/31

File easter.c (*) provides a function that computes the date of Easter. The other holidays can be computed by using easter and the methods implemented above.

Solution:

Alternative solution:

Discussion of solution (*)