FRIDAY THE 13TH
When will Friday the 13th occur in 1990? Write a program that will
find all months in 1990 in which the 13th falls on a Friday.
You need to know the following.
1. January 1, 1990 was on a Monday.
2. September, April, June, and November have thirty days, all the rest
have 31 except for February which has 28 except in leap years when it has 29.
3. 1990 is not a leap year.
Note: To make it fair for everyone, you may not use any built-in date
functions from your computer language.
Sample Run
In 1990, Friday the 13th occurs in the months:
APRIL
Source.cpp
#include <iostream>
#include <iomanip>
#include "Date.h"
using namespace std;
void iterateMonth(int);
bool isFriday13th();
string dayofweek[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "" };
string month[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "" };
//int dayInMonth[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
//int dayInMonthLeap[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
void iterateMonth(int year) {
int dayCode, month, daysInMonth, day, u;
bool leapYear;
cout << year;
// returns the day on which January 1 of year begins.
dayCode = Date::getDayCode(year);
// returns true if year is a leap year, false otherwise
leapYear = Date::isLeap(year);
// month is 0 for Jan, 1 for Feb, etc.
for (month = 1; month <= 12; month++)
{
switch (month)
{
case 1:
cout << "\n\nJanuary\n";
daysInMonth = 31;
break;
case 2:
cout << "\n\nFebruary\n";
if (leapYear)
daysInMonth = 29;
else
daysInMonth = 28;
break;
case 3:
cout << "\n\nMarch\n";
daysInMonth = 31;
break;
case 4:
cout << "\n\nApril\n";
daysInMonth = 30;
break;
case 5:
cout << "\n\nMay\n";
daysInMonth = 31;
break;
case 6:
cout << "\n\nJune\n";
daysInMonth = 30;
break;
case 7:
cout << "\n\nJuly\n";
daysInMonth = 31;
break;
case 8:
cout << "\n\nAugust\n";
daysInMonth = 31;
break;
case 9:
cout << "\n\nSeptember\n";
daysInMonth = 30;
break;
case 10:
cout << "\n\nOctober\n";
daysInMonth = 31;
break;
case 11:
cout << "\n\nNovember\n";
daysInMonth = 30;
break;
case 12:
cout << "\n\nDecember\n";
daysInMonth = 31;
break;
}
//cout << "\n\nSun Mon Tue Wed Thu Fri Sat\n";
for (int i = 0; i < (sizeof(dayofweek) / sizeof(dayofweek[0])); i++)
{
cout << dayofweek[i] << " ";
}
cout << endl;
for (day = 1; day <= dayCode * 5; day++)
{
cout << " ";
}
for (day = 1; day <= daysInMonth; day++)
{
cout << setw(3) << day;
if ((day + dayCode) % 7 > 0)
{
cout << " ";
}
else
cout << endl;
}
dayCode = (dayCode + daysInMonth) % 7;
}
}
//bool isFriday13th() {
//
//}
int main() {
int year;
//cout << "Please enter a year: ";}
Comments
Leave a comment