#include <iostream.h> #include <stdlib.h> #include <ctype.h> #include <time.

h> int getYear(); // has the user enter a valid year bool isLeap(int year); // check for leap years void dayName(); // prints the names for the day of the week void monthNameHeader(int year); // puts head for the month name int startDay(int year); // decides what week day Jan starts on int monthCount(int counter); // how many days are in each month void newMonth(int startDOW); void printAll(int year); to screen // what day of the week new month starts on // puts everything together, prints

int year = 0; per 0 int counter = 1; days in month int startDOW, wrap, Saturday daysInMonth; int weekNumber = 0; int main() {

// uesr inputed year || rand gen // counter for month name & # // day of the week Jan starts on // check for if weekday is // total days in each month // flag for first week of the month

year = getYear(); printAll(year);

// has user enter year number

return 0; }

int getYear() //prompts the user to enter a valid year { char c; srand(time(NULL)); cout << "Enter the year, or 0 for and random year: "; do { // gets whole number value cin.get(c); if(isdigit(c)) { year=year*10; year +=(int)(c-'0');

if (year % 100 == 0) return false. if (year % 4 == 0) return true.} } while(c!='\n'). February " << year << endl. random a year { year = rand() % 8600 + 1400. case 2: cout << " break. case 3: cout << " break. return false. // else return false } void dayName() { cout << " S M T W T F S" << endl. } void monthNameHeader(int year) { switch (counter) { case 1: cout << " break. case 4: cout << " break. case 5: cout << " break. case 6: cout << " January " << year << endl. } return year. cout << "---------------------" << endl. April " << year << endl. June " << year << endl. if (year == 0) // if no response or 0 are enter. . May " << year << endl. cout << "\nThe random year " << year << " will be evaluated\n\n". } bool isLeap(int year) // checking for possible leap year { if (year % 400 == 0) return true. March" << year << endl.

case 12: cout << " break. October " << year << endl. case 7: cout << " break. November " << year << endl. . August " << year << endl. case 4: daysInMonth = 30. } } int monthCount(int counter) // how many days are in the month { switch (counter) { case 1: daysInMonth = 31. break. case 2: possible leap year if(isLeap(year)) daysInMonth = 29. case 11: cout << " break. // current month days break. September " << year << endl. break. case 8: cout << " break. case 9: cout << " break. if(!isLeap(year)) daysInMonth = 28. break. case 10: cout << " break. case 5: daysInMonth = 31.break. // checks for July " << year << endl. December " << year << endl. break. case 3: daysInMonth = 31.

month day dayName(). break. break. return startDOW. case 7: daysInMonth = 31. break. case 10: daysInMonth = 31. counter <= 12.1) / 100 + (year . // formula for what DoWeek year starts on } void printAll(int year) { for (counter = 1. break. case 12: daysInMonth = 31. case 8: daysInMonth = 31. break. prints the name of days if (counter==1) wrap = startDay(year) .case 6: daysInMonth = 30.1 ) /4 . counter++) { monthNameHeader(year). } } int startDay(int year) { startDOW = (year + (year . break.1) /400) %7.(year . on else // // what day Jan starts // prints . case 11: daysInMonth = 30. case 9: daysInMonth = 30. break.

dayCounter++) { if (wrap == 7) return { cout << "\n ". other months start on cout << " ". wrap = 0. of week counter weekNumber++. *testing* cout << "\ndays in this month are " << daysInMonth. system("PAUSE"). month for (int dayCounter=1. // what day for (int loopCount = 0. // how many space to indent new month } monthCount(counter). cout << endl.startDOW = wrap. carriage // how many days in } . week of month } if (dayCounter<10) single digit days cout << " ". loopCount < startDOW. } // end BIG for loop //prints the day //adds space for //no longer first //resets day //if Saturday. } // // cout << "\nthis month starts on day number " << startDOW. *testing* cout << "\n\n". # wrap++. cout << dayCounter << " ".dayCounter<=daysInMonth. loopCount++) { cout << " ".

Sign up to vote on this title
UsefulNot useful