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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/*************************************
Leap Year function returns true/false if test is leap year/is not leap year, respectively - called by calendar function
*************************************/
bool leapYear(int test)
{
int remainder;
remainder = test%4;
if(remainder==0)
{
if (test%100 == 0)
{
remainder = test%400;
if (remainder==0)
return true;
else
return false;
}
else
return true;
}
else
return false;
}// leapYear function
/*************************************
century function calculates what century a year is to apply it to the math in calendar function
*************************************/
int century(int gregorianyear)
{
int temp;
gregorianyear = gregorianyear/100;
temp = gregorianyear;
top:
if(temp==19)
return 0;
else if(temp==20)
return 5;
else if(temp==21)
return 4;
else if(temp==22)
return 2;
else
{
temp = temp - 4;
goto top;
}
}//century
/************************************
leapdays function returns the number of leapdays as needed for calender function
***********************************/
int leapdays(int year, int month)
{
int temporary,counter, loop;
counter = 0;
for(loop=25; loop > 0; loop--)
{
temporary = year%4;
if (temporary==0)
{
year = year/4;
counter = counter+1;
if (year==0)
break;
}
else
year= year-1;
}
if (temporary == 0)
{
if(month==1 || month==2)
counter = counter-1;
}
return counter;
}//leapdays
/****************************************
getmonth function takes month to convert it for math in calendar
*****************************************/
int getmonth(int inputmonth)
{
//originally I had less statements with || separating those with similar
//returns, but the logic only worked with 12 separate statements.
if (inputmonth == 1)
return 0;
else if (inputmonth == 2)
return 3;
else if (inputmonth ==3)
return 3;
else if (inputmonth == 4)
return 6;
else if (inputmonth == 5)
return 1;
else if (inputmonth == 6)
return 4;
else if (inputmonth ==7)
return 6;
else if (inputmonth == 8)
return 2;
else if (inputmonth == 9)
return 5;
else if (inputmonth == 10)
return 0;
else if (inputmonth == 11)
return 3;
else if (inputmonth == 12)
return 5;
}//getmonth
/*************************************
calendar function takes a month,day,year to calculate the day of year - calls leapyear and century functions
*************************************/
void calendar ()
{
int month,day,year, lasttwo, temp,x;
int total;
bool leap = false;
cout << "LAST FUNCTION, TELLS WHAT DAY OF WEEK A PARTICULAR DAY IN A YEAR IS." << endl;
cout << "What month? (1-12)";
cin >> month;
cout << endl;
cout << "What day? (1-31)";
cin >> day;
cout << endl;
cout << "What year? (>=1901)";
cin >> year;
cout << endl;
if (leapYear(year))
{
cout << year << " is a leap year." << endl;
}
else
{
cout << year << " is not a leap year." << endl;
}
total = (century(year)+ year%100 + leapdays(year,month)+ getmonth(month)+ day)%7;
if (total==0)
cout << "It was a Sunday on " << month << "-" << day << "-" << year << endl;
else if (total==1)
cout << "It was a Monday on " << month << "-" << day << "-" << year << endl;
else if (total==2)
cout << "It was a Tuesday on " << month << "-" << day << "-" << year << endl;
else if (total==3)
cout << "It was a Wednesday on " << month << "-" << day << "-" << year << endl;
else if (total==4)
cout << "It was a Thursday on " << month << "-" << day << "-" << year << endl;
else if (total==5)
cout << "It was a Friday on " << month << "-" << day << "-" << year << endl;
else if (total==6)
cout << "It was a Saturday on " << month << "-" << day << "-" << year << endl;
}//calender function
|