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
|
#include <iostream>
int printMonthCalender(int numOfDays, int startingDay);
int leapYearCheck(int year);
void printYearCalender(int year, int startingDay);
int main()
{
std::cout << "Please enter the number of days in the month: ";
int numDays;
std::cin >> numDays;
std::cout << "Please enter a number for the day of the week were first number starts: ";
int typeDay;
std::cin >> typeDay;
std::cout << "Please enter year: ";
int desiredYear;
std::cin >> desiredYear;
// std::cout << printMonthCalender(numDays,typeDay) << '\n';
printYearCalender(desiredYear, typeDay);
std::cin.ignore(2);
return 0;
}
int printMonthCalender(int numOfDays, int startingDay)
{
std::cout << "Mon\tTue\tWed\tThr\tFri\tSat\tSun\n";
// spacing for 1st week
for (int startDay = 1; startDay < startingDay; startDay++) { std::cout << '\t'; }
//days in first week
for (int count = 1; count <= 8 - startingDay; count++) { std::cout << count << '\t'; }
std::cout << '\n';
//loop for every week 6 # in the week ie 5-11, 12-18
int countDays = 9 - startingDay;
for (int count = 1;
count <= numOfDays && countDays <= numOfDays;
count++, countDays++) {
if (count % 7 == 0) { std::cout << '\n'; }
std::cout << countDays << '\t';
}
return countDays;
}
int leapYearCheck(int year)
{
int numOfDays;
// assuming user input is friendly and does not put year before Gregorian calendar
if ((year % 4) == 0)
{
if (year % 100 == 0 && year % 400 != 0) { numOfDays = 28; } // February
else { numOfDays = 29; }
}
else
{
numOfDays = 28;
}
return numOfDays;
}
void printYearCalender(int year, int startingDay)
{
// march, april, may, june, july, august, september, october, november, december;
int numOfDays;
std::cout << "January " << year << '\n';
int january = printMonthCalender(31, startingDay);
std::cout << '\n';
//can't figure out spacing for the beginning of the months after jan
std::cout << "Feburary " << year << '\n';
int feburary = printMonthCalender(leapYearCheck(year), startingDay);
std::cout << '\n';
// call function leapYearCheck
// leapYearCheck(year)
std::cout << "March " << year << '\n';
int march = printMonthCalender(31, startingDay);
std::cout << "April " << year << '\n';
int april = printMonthCalender(30, startingDay);
std::cout << "May " << year << '\n';
int may = printMonthCalender(31, startingDay);
std::cout << "June " << year << '\n';
int june = printMonthCalender(30, startingDay);
std::cout << "July " << year << '\n';
int july = printMonthCalender(31, startingDay);
std::cout << "August " << year << '\n';
int august = printMonthCalender(31, startingDay);
std::cout << "September " << year << '\n';
int september = printMonthCalender(30, startingDay);
std::cout << "October " << year << '\n';
int october = printMonthCalender(31, startingDay);
std::cout << "November " << year << '\n';
int november = printMonthCalender(30, startingDay);
std::cout << "December " << year << '\n';
int december = printMonthCalender(31, startingDay);
}
|