Calendar C
Calendar C
com/snippets/calendar-calculation-c
view source
print?
01.#include <iostream>
02.#include <fstream>
03.#include <string>
04.
05.using namespace std;
06.
07.bool isLeapYear(int year) {
08.
09.
if (year % 100 == 0) {
10.
if (year % 400 == 0) {
11.
retval = true;
12.
13.
}
} else if (year % 4 == 0) {
14.
retval = true;
15.
16.
17.}
return retval;
18.
19.int daysInMonth(int month, int year) {
20.
switch (++month) {
21.
case 4:
22.
case 6:
23.
case 9:
24.
case 11:
25.
return 30;
26.
break;
case 2:
27.
if (isLeapYear(year)) {
28.
return 29;
29.
30.
31.
break;
32.
default:
33.
return 31;
34.
break;
35.
36.}
37.
38.int getFirstDayOfMonth(int month, int year, int day) {
1 of 3
39.
40.
int numdays;
41.
if (month == 0) {
08/18/2012 05:38 PM
http://www.dzone.com/snippets/calendar-calculation-c
42.
43.
44.
45.
46.
47.
48.
49.
retval = 1;
} else {
50.
51.
52.
53.
54.}
return retval;
55.
56.int getThirteenth(int firstday) {
57.
58.}
59.
60.int main() {
61.
62.
63.
64.
int numYears;
65.
66.
67.
int firstDay[numYears][12];
68.
int numThirteenths[7];
69.
int day;
70.
71.
72.
73.
74.
75.
76.
firstDay[x][month] = 1;
77.
78.
} else if (month == 0) {
79.
firstDay[x-1][11]);
80.
81.
firstDay[x][month-1]);
2 of 3
82.
83.
++numThirteenths[((firstDay[x][month] + 5) % 7)];
08/18/2012 05:38 PM
http://www.dzone.com/snippets/calendar-calculation-c
84.
85.
++year;
86.
87.
88.
89.
for (int y = 0; y < 5; ++y) fout << numThirteenths[y] << " ";
90.
91.
92.
93.}
3 of 3
return 0;
08/18/2012 05:38 PM