-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalendar creator.cpp
153 lines (113 loc) · 4.28 KB
/
Calendar creator.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Calendar creator: This program creates a yearly calendar.
// The user inputs the year and the first day of the year.
// The calendar takes into account leap years and prints out the appropriate calendar.
// By Daniel Romero.
#include <iostream>
using namespace std;
int printMonthCalendar(int numOfDays, int startingDay);
void printYearCalendar(int year, int startingDay);
bool leapYear(int year);
int main()
{
int year, startingDay, inputDay;
cout << "Welcome to Calendar creator. " << endl;
cout << "Please enter the year of the calendar you want to make ";
cin >> year;
cout << endl << "Please enter starting day of the year (1 for Monday...7 for Sunday) ";
cin >> inputDay;
cout << endl;
startingDay = inputDay - 1;
cout << endl; printYearCalendar (year, startingDay);
return 0;
}
void printYearCalendar(int year, int startingDay)
{
// January
cout << "January " << year << endl;
startingDay = printMonthCalendar(31, startingDay);
// February
bool flag = leapYear(year);
if (flag == true)
{
cout << "February " << year << endl;
startingDay = printMonthCalendar(29, startingDay);
}
else
{
cout << "February " << year << endl;
startingDay = printMonthCalendar(28, startingDay);
}
// March
cout << "March " << year << endl;
startingDay = printMonthCalendar(31, startingDay);
// April
cout << "April " << year << endl;
startingDay = printMonthCalendar(30, startingDay);
// May
cout << "May " << year << endl;
startingDay = printMonthCalendar(31, startingDay);
// June
cout << "June " << year << endl;
startingDay = printMonthCalendar(30, startingDay);
// July
cout << "July " << year << endl;
startingDay = printMonthCalendar(31, startingDay);
// August
cout << "August " << year << endl;
startingDay = printMonthCalendar(31, startingDay);
// September
cout << "September " << year << endl;
startingDay = printMonthCalendar(30, startingDay);
// October
cout << "October " << year << endl;
startingDay = printMonthCalendar(31, startingDay);
// November
cout << "November " << year << endl;
startingDay = printMonthCalendar(30, startingDay);
// December
cout << "December " << year << endl;
startingDay = printMonthCalendar(31, startingDay);
}
int printMonthCalendar(int numOfDays, int startingDay)
{
cout << "Mon Tue Wed Thu Fri Sat Sun" << endl;
int k;
for (k = 0; k < startingDay; k++)
cout << '\t';
for (int j = 1; j <= numOfDays; j++)
{
cout << j << '\t';
if (++k > 6)
{
k = 0;
cout << '\n';
}
}
if (k)
cout << '\n';
startingDay = k;
cout << endl;
return startingDay;
}
bool leapYear(int year)
{
bool isLeapYear = false;
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
isLeapYear = true;
}
}
else isLeapYear = true;
}
return isLeapYear;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file