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
|
#include <cstdlib>
#include <iostream>
using namespace std;
const int NUMBER_OF_MONTHS=12;
void printTitleOfCalendar(string months[],int i){
cout<<" "<<months[i]<<endl;
cout<<" Sun Mon Tue Wed Thu Fri Sat \n";
}
void printDaysOfCalendar(int i,int daysOfMonth[],int j){
for(i=1;i<=daysOfMonth[j];i++){
if(i<=9) //Prints all 12 months of the year
cout<<" "<<i<<" ";
if(i>9)
cout<<" "<<i<<" ";
if(i%7==0)
cout<<endl<<endl;
}
}
void checkLeapYear(int userInput,int daysOfMonth[]){ //Check if the year is a leapyear
if(userInput%4==0)
daysOfMonth[1]=29;
if(userInput%100==0)
daysOfMonth[1]=28;
if(userInput%400==0)
daysOfMonth[1]=29;
}
void startDayOfMonth(int startDOW){
if(startDOW==1)
cout<<" ";
//Start on the right day of the month
}
int main(int argc, char *argv[]){
int startDOW,userInput,i=0,j=0,daysOfMonth[]={31,28,31,30,31,30,31,31,30,31,30,31};
string months[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
cout<<"Enter in the year of the calendar: ";
cin>>userInput;
cout<<endl;
checkLeapYear(userInput,daysOfMonth);
startDOW=(userInput+(userInput-1)/4-(userInput-1)/100+(userInput-1)/400)%7; //This is the algorithm that outputs a 0-6 for which day the month starts on
for(i=0;i<NUMBER_OF_MONTHS;i++){
printTitleOfCalendar(months,i);
startDayOfMonth(startDOW);
printDaysOfCalendar(i,daysOfMonth,i);
cout<<endl<<endl;
}
cout<<startDOW;
system("PAUSE");
return EXIT_SUCCESS;
}
| |