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
|
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
const string MONTHARRAY[12] = { " January", " February", " March", " April", " May", " June", " July", " August", " September", " October", " November", " December"};
const string DAYARRAY[7] = {"Sun ", " Mon ", " Tue ", " Wed ", " Thu ", " Fri ", " Sat"};
int a,y,day,m,d, x;
int month;
void printMonth(int month, int startDay, int year);
int getFirst(int month, int day, int year);
int main (void)
{
cout<<"Please enter a year later than 1582: ";
cin>>x;
if(x>1582){
for (int i = 0; i<12; i++) {
getFirst(i, 1, x);
printMonth(i, d, x);
}
}
else{
cout<<"That year is before 1582, please enter a better year: ";
cin>>x;
}
return 0;
}
int getFirst(int month, int day, int year){
a = (14-month)/12;
y = year-a;
m = month+12*a-2;
d = (day+y+y/4-y/100+y/400+(31*m/12))%7;
return d;
}
void printMonth(int month, int startDay, int year){
int daysInMonths[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int copy = 1;
int counter = 1;
cout<<MONTHARRAY[month]<<endl;
if(year%4 == 0)
daysInMonths[1] = 29;
for(int i = 0; i <=6; i++){
cout<<DAYARRAY[i];
if(i == 6)
cout<<endl;
}
while(copy<=daysInMonths[month]){
if(counter <= startDay)
cout<<left<<setw(5)<<" ";
else{
cout<<left <<setw(5) <<copy;
copy++;
}
if(counter%7 == 0 )
cout<<endl;
counter++;
}
cout<<endl;
}
|