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
|
#include <iostream>
using namespace std;
void printOneMonth(int month, int& dow, int year);
void daysInMonth(int month, int year, int& dim);
bool isLeapYear(int year);
int main(){
int year=0, dow, count;
cout << "Please enter the year: " << endl;
cin >> year;
cout << "Please enter the day of the week for January 1st: " << endl;
cin >> dow;
for(count=1; count<=12; count++){
printOneMonth(count, dow, year);
cout << endl;
}
return 0;
}
void printOneMonth(int month, int& dow, int year){
switch(month)
{
case 1: cout << "January";
break;
case 2: cout << "Februrary";
break;
case 3: cout << "March";
break;
case 4: cout << "April";
break;
case 5: cout << "May";
break;
case 6: cout << "June";
break;
case 7: cout << "July";
break;
case 8: cout << "August";
break;
case 9: cout << "September";
break;
case 10: cout << "October";
break;
case 11: cout << "November";
break;
case 12: cout << "December";
break;
}
}
void daysinMonth(int month, int year, int& dim){
switch(month)
{
case 1:
dim=31;
break;
case 2:
if(isLeapYear(year))
{
dim=29;
}
else if(!isLeapYear(year))
{
dim=28;
}
break;
case 3:
dim=31;
break;
case 4:
dim=30;
break;
case 5:
dim=31;
break;
case 6:
dim=30;
break;
case 7:
dim=31;
break;
case 8:
dim=31;
break;
case 9:
dim=30;
break;
case 10:
dim=31;
break;
case 11:
dim=30;
break;
case 12:
dim=31;
break;
}
}
bool isLeapYear(int year){
if (year % 400 == 0 || year%100 != 0 && year%4 == 0)
{
return true;
}
else
{
return false ;
}
}
|