-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKalendar.cpp
90 lines (73 loc) · 2.26 KB
/
Kalendar.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
#include <iostream>
#include <string>
#include <iomanip>
#include <conio.h>
#include <time.h>
void printCalendar(int year) {
int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
int mDays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
std::string monthList[] = { "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" };
std::cout << " --------------------------" << std::endl;
std::cout << " Calender - "<< year << std::endl;
std::cout << " ---------------------------" << std::endl;
int days;
int current;
int y = year - 1;
current = ( y + y/4 - y/100 + y/400 + t[0] + 1) % 7;
for (int i = 0; i < 12; i++) {
if (i == 1) {
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
days = 29;
} else {
days = mDays[i];
}
} else {
days = mDays[i];
}
std::cout << std::endl << " -------------" << monthList[i] << "--------" << std::endl;
std::cout << " Sun Mon Tue Wed Thu Fri Sat" << std::endl;
int k;
for (k = 0; k < current; k++) {
std::cout << " ";
}
for (int j = 1; j <= days; j++) {
k++;
std::cout << std::setw(5) << j;
if (k > 6) {
k = 0;
std::cout << std::endl;
}
}
if (k) {
std::cout << std::endl;
}
current = k;
}
}
int main() {
system("cls");
time_t ttime = time(0);
tm *local_time = localtime(&ttime);
int year = 1900 + local_time -> tm_year;
char option;
do {
system("cls");
printCalendar(year);
std::cout << std::endl << std::endl;
std::cout << "Press " << std::endl;
std::cout << "- n for next year" << std::endl;
std::cout << "- p for previous year" << std::endl;
std::cout << "- e for exit" << std::endl;
option = getche();
switch(option) {
case 'n':
year++;
break;
case 'p':
year--;
break;
}
}
while(option != 'e' && option != 'E');
return 0;
}