This assignment will provide you with practice both on conditions and loop statements. You should structure your program into functions performing single tasks and test your program one subprogram at a time using drivers.
The DatesRUs calendar company has decided to write a calendar program to generate calendars for years between 1800 and 2499. They want you to produce a program that prompts a user for a month (entered as a number between 1 and 12) and a year (entered as a number between 1800 and 2499) and then have the program print out a calendar for that month in that year. Samples of the output of the program are shown below:
-------------------------------------------------
Welcome to the DatesRUs Calendar program!
This program will prompt you for a month and year
and will print a calendar for that month. To
enter the month you will type a number between
1 and 12 representing the months January (1),
February (2), March (3) and so on. The year
must be a number between 1800 and 2499.
Enter month (1-12) of calendar to print: 1
Enter year (1800-2499) of month to print: 1800
January 1800
M Tu W Th F Sa Su
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
-------------------------------------------------
Welcome to the DatesRUs Calendar program!
This program will prompt you for a month and year
and will print a calendar for that month. To
enter the month you will type a number between
1 and 12 representing the months January (1),
February (2), March (3) and so on. The year
must be a number between 1800 and 2499.
Enter month (1-12) of calendar to print: 2
Enter year (1800-2499) of month to print: 1900
February 1900
M Tu W Th F Sa Su
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
-------------------------------------------------
Welcome to the DatesRUs Calendar program!
This program will prompt you for a month and year
and will print a calendar for that month. To
enter the month you will type a number between
1 and 12 representing the months January (1),
February (2), March (3) and so on. The year
must be a number between 1800 and 2499.
Enter month (1-12) of calendar to print: 3
Enter year (1800-2499) of month to print: 2001
March 2001
M Tu W Th F Sa Su
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
-------------------------------------------------
Welcome to the DatesRUs Calendar program!
This program will prompt you for a month and year
and will print a calendar for that month. To
enter the month you will type a number between
1 and 12 representing the months January (1),
February (2), March (3) and so on. The year
must be a number between 1800 and 2499.
Enter month (1-12) of calendar to print: 0
Please use a number between 1 and 12!
Enter month (1-12) of calendar to print: 13
Please use a number between 1 and 12!
Enter month (1-12) of calendar to print: 15
Please use a number between 1 and 12!
Enter month (1-12) of calendar to print: -2
Please use a number between 1 and 12!
Enter month (1-12) of calendar to print: 12
Enter year (1800-2499) of month to print: 2500
Please use a number between 1800 and 2499!
Enter year (1800-2499) of month to print: 0
Please use a number between 1800 and 2499!
Enter year (1800-2499) of month to print: 239 9
Please use a number between 1800 and 2499!
Enter year (1800-2499) of month to print: Please use a number between 1800 and 2499!
Enter year (1800-2499) of month to print: 2499
December 2499
M Tu W Th F Sa Su
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
-------------------------------------------------
if (Year X is a leap year)
Jan1Day += 366;
else
Jan1Day += 365;
Jan1Day = Jan1Day % 7;
if (Jan1Day == 0)
Jan1Day = 7;
Jan1Day now is the day of the week January 1 in year X+1
falls on.
Note, you will have to fill in the appropriate test for determining if
Year X is a leap year in the above code.
Since your program will be heavily modularized, be sure to test each function individually as you progress.
Hand in a full lab report for your program. For your tests you should show the enough different combinations of month and year to conclude that your program produces the correct output for all of the month and year combinations.
(7 points) When the user types 0 for the month, print out a calendar for the entire year with three columns of months (and four rows). The format of the full year calendar would be:
Enter month (0-12) of calendar to print: 0
Enter year (1800-2499) of month to print: 2000
2000
Jan Feb Mar
M Tu W Th F Sa Su M Tu W Th F Sa Su M Tu W Th F Sa Su
1 2 1 2 3 4 5 6 1 2 3 4 5
3 4 5 6 7 8 9 7 8 9 10 11 12 13 6 7 8 9 10 11 12
10 11 12 13 14 15 16 14 15 16 17 18 19 20 13 14 15 16 17 18 19
17 18 19 20 21 22 23 21 22 23 24 25 26 27 20 21 22 23 24 25 26
24 25 26 27 28 29 30 28 29 27 28 29 30 31
31
Apr May Jun
M Tu W Th F Sa Su M Tu W Th F Sa Su M Tu W Th F Sa Su
1 2 1 2 3 4 5 6 7 1 2 3 4
3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
24 25 26 27 28 29 30 29 30 31 26 27 28 29 30
Press return to continue.
Jul Aug Sep
M Tu W Th F Sa Su M Tu W Th F Sa Su M Tu W Th F Sa Su
1 2 1 2 3 4 5 6 1 2 3
3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
31
Oct Nov Dec
M Tu W Th F Sa Su M Tu W Th F Sa Su M Tu W Th F Sa Su
1 1 2 3 4 5 1 2 3
2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
30 31
Press return to finish.