Challenge (1)

CS1440- Summer 2002

 

Write a C++ program that prints a calendar for a given year. The program prompts the user for three inputs;

1) The year for which you are generating the calendar.

2) The day of the week that January first is on, you will use the following notation to set the day of the week:

0 Sunday 1 Monday 2 Tuesday 3 Wednesday

4 Thursday 5 Friday 6 Saturday

 

3) The output file name.

 

Your program should generate the calendar similar to the one shown in the example output below. The calendar should be printed into the output file. Your program should be able to handle leap years. A leap year is a year in which we have 366 days. That extra day comes at the end of February. Thus, a leap year have 366 days with 29 days in February. A century year is a leap year if it is devisable by 400. Other years devisable by 4 but not by 100 are also leap years. Example: year 2004 is a leap year but year 2100 is not a leap year. 2000 is devisable by 400, 2100 is devisable by 100.

 

You can use as many functions as you wish. Your code has to clearly describe its functionality and the instructions on how to run it.

 

Sample Input:

 

Please enter the year for which you wish to generate the calendar: 2004

Please enter the day of the week that January first is on: 4

 

Please note that day 4 corresponds to Thursday.

 

Sample output:

 

Calendar for year 2004

January

 

Sun Mon Tue Wed Thu Fri Sat

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

 

February

 

Sun Mon Tue Wed Thu Fri Sat

1 2 3 4 5 6 7

.. .. .. .. .. ..

.. ..

..

..

 

You need to use a function that reads the name of the output file name and will return the input stream to the main.