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
|
#include <iostream>
#include <string>
using namespace std;
void calendar (int year, int start_day);
bool leap_year (int year);
int nums_month (int count, int& days_month, int year);
int main()
{
int start_day;
int year;
cout << "Which year of the calendar do you want?" << endl;
cin >> year;
cout << "Which day do you want January 1st to start on?" << endl << "Ex: Sunday = 0, Monday = 1, Tuesday = 2, etc" << endl;
cin >> start_day;
calendar(year,start_day);
}
void calendar (int year, int start_day)
{
int days_month;
int count;
int i = 1;
int count_col = 0;
string months[12] = {"January","February","March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
for (count = 0; count < 12; count++)
{
cout << months[count] << endl;
cout << " S M TU W TH F S " << endl;
nums_month(count, days_month,year);
while (i <= days_month)
{
if (count_col == 7)
{
cout << endl;
count_col = 0;
}
cout << " " << i << " ";
count_col++;
i++;
}
count_col = 0;
i = 1;
cout << endl << endl;
}
}
bool leap_year (int year){
if (year % 400 == 0){
return true;
}
if (year % 100 == 0){
return true;
}
if (year % 4 == 0){
return true;
}
return false;
}
int nums_month (int count, int& days_month, int year)
{
switch (count)
{
case 0:
days_month = 31;
break;
case 1:
if (leap_year(year))
days_month = 29;
if (!leap_year(year))
days_month = 28;
break;
case 2:
days_month = 31;
break;
case 3:
days_month = 30;
break;
case 4:
days_month = 31;
break;
case 5:
days_month = 30;
break;
case 6:
days_month = 31;
break;
case 7:
days_month = 31;
break;
case 8:
days_month = 30;
break;
case 9:
days_month = 31;
break;
case 10:
days_month = 30;
break;
case 11:
days_month = 31;
break;
}
return 0;
}
|