forked from Rockzzzz-221/CPP-Files
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalender.cpp
More file actions
94 lines (79 loc) · 1.7 KB
/
calender.cpp
File metadata and controls
94 lines (79 loc) · 1.7 KB
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
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <time.h>
using namespace std;
void printCalender(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};
string monthList[] = { "January", "February","March", "April","May", "June", "July", "August", "September", "October", "November", "December"};
cout<<" ----------------------------------------"<<endl;
cout<<" Calender :"<<year<<endl;
cout<<" ----------------------------------------"<<endl<<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 !=100))
{
days = 29;
}
else
{
days = mDays[i];
}
}
else
days = mDays[i];
cout<<endl<<" -------------" <<monthList[i]<<"---------------"<<endl;
cout<<" Sun Mon Tue Wed Thu Fri Sat"<<endl;
int k;
for (k= 0; k< current; k++)
cout<<" ";
for(int j =1; j <= days; j++)
{
k++;
cout<<setw(5)<<j;
if (k>6)
{
k= 0;
cout<<endl;
}
}
if (k)
cout<<endl;
current = k;
}
return ;
}
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");
printCalender(year);
cout<<endl<<endl;
cout<<"Press "<<endl;
cout<<"- n for next year"<<endl;
cout<<"- p for previous year"<<endl;
cout<<"- e for Exit"<<endl;
option = getche();
switch(option){
case 'n':
year++;
break;
case 'p':
year --;
}
}while(option!='e' && option!='E');
return 0;
}