Print the Calendar of a Month
- You have learned how to calculate the
beginning day of a month,
and how to
print the calendar of January given
the 1st day.
Now combine these two skills to print the calendar of any given month.
- This slightly differs from the task of
printing the calendar of January,
where January always has 31 days.
You must determine how many days are there in a month, which you learned
to handle with a
switch statement
in the homework of
beginning day of a month.
- Because the width of each month name may be different, if you want
to center-justify the month name and your number, you can not always
print 4 spaces in front of the month name, as you did for January.
- For "May", you need 6 spaces.
For "March", you need 5 spaces.
So this depends on the width of the month name.
- Therefore, you have to determine the month_width and year_width,
and print
(20-(month_width + 1 + year_width))/2
spaces in front of the month name.
The program may run as follows:
2016 3
March 2016
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31