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 115 116 117 118 119 120 121 122 123 124
|
/**********************************************************************
* This function will determine the offset which determines what the
* first day of the month starts on.
***********************************************************************/
int offSetDay(int yearNumber, int monthNumber)
{
int offSet;
offSet = (totalDaysPastYears(yearNumber) + totalDaysinCurrentYear
(yearNumber, monthNumber)) % 7;
return offSet;
}
/**********************************************************************
* This function will tell us how many days are in a given
* month.
***********************************************************************/
int numDaysinMonth(int monthNumber)
{
int yearNumber;
if (monthNumber == 1)
return 31;
else if (monthNumber == 2)
{
if (isLeapYear(yearNumber) == true)
return 29;
else
return 28;
}
else if (monthNumber == 3)
return 31;
else if (monthNumber == 4)
return 30;
else if (monthNumber == 5)
return 31;
else if (monthNumber == 6)
return 30;
else if (monthNumber == 7)
return 31;
else if (monthNumber == 8)
return 31;
else if (monthNumber == 9)
return 30;
else if (monthNumber == 10)
return 31;
else if (monthNumber == 11)
return 30;
else if (monthNumber == 12)
return 31;
}
/**********************************************************************
* This function will display a calendar that will start given the
* and end depending on how many days are in the month.
***********************************************************************/
void displayTable(int yearNumber, int monthNumber)
{
int days;
cout << " Su Mo Tu We Th Fr Sa\n";
if (offSetDay(yearNumber, monthNumber) == 0)
cout << setw(5); //Monday
else if (offSetDay(yearNumber, monthNumber) == 1) //Tuesday
cout << setw(9);
else if (offSetDay(yearNumber, monthNumber) == 2) //Wednesday
cout << setw(13);
else if (offSetDay(yearNumber, monthNumber) == 3) //Thursday
cout << setw(17);
else if (offSetDay(yearNumber, monthNumber) == 4) //Friday
cout << setw(21);
else if (offSetDay(yearNumber, monthNumber) == 5) //Saturday
cout << setw(25);
else if (offSetDay(yearNumber, monthNumber) == 6) //Sunday
cout << setw(1);
for (days = 1; days <= numDaysinMonth(monthNumber); days++)
{
cout << " " << setw(3) << days;
if (days + 1 + offSetDay(yearNumber, monthNumber)
% 7 == 0 && days < numDaysinMonth(monthNumber))
cout << "\n";
}
}
/*********************************************************************
* Main will call the functions above to display a month calendar of
* a given year.
*********************************************************************/
int main()
{
int monthNumber;
int yearNumber;
int offSet;
monthNumber = getMonth();
yearNumber = getYear();
displayMonth(monthNumber);
cout << yearNumber << endl;
displayTable(yearNumber, monthNumber);
cout << endl;
return 0;
}
|