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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
// This program will be used to print a calendar for any givn year and the day of the week
#include <iostream>
#include <iomanip>
void printCal(int year, int start);
using namespace std;
//Function 1
//Prints Calendar
void printCal(int year, int start, int monthDays, int spacerDays, int prevSpacer, int dayCount = 1, int colCount = 0)
{
void monthNames(int count);
void dayNames();
void monthNums(int count, int& monthDays, int& spacerDays);
void spacer(int start, int& colCount, int count, int& prevSpacer);
void wrapper(int dayCount, int monthDays);
int count;
for (count = 1; count <= 12; count++)
{
monthNames(count);
dayNames();
monthNums(count, monthDays, spacerDays);
spacer(start, colCount, count, prevSpacer);
wrapper(dayCount, monthDays);
}
}
//Function 2
//Makes The Lines Return
void wrapper(int dayCount, int monthDays, int colCount)
{
while (dayCount <= monthDays)
{
if (colCount == 7)
{
cout << endl;
colCount = 0;
}
cout << setw(3);
cout << dayCount;
colCount++;
dayCount++;
}
colCount = 0;
cout << endl << endl;
}
//Function 3
//Checks For Leap Year
bool leapYear(int year)
{
if (year % 400 == 0)
{
return true;
}
if (year % 100 == 0)
{
return false;
}
if (year % 4 == 0)
{
return true;
}
return false;
}
//Function 4
//Previous And Current Days In Each Month
void monthNums(int& count, int& monthDays, int& spacerDays, int year, int monthCount)
{
switch (count)
{
case 1:
monthDays = 31;
break;
case 2:
if(leapYear(year))
//Check For Leap Year
monthDays = 29;
if(!leapYear(year))
monthDays = 28;
spacerDays = 31;
break;
case 3:
monthDays = 31;
if(leapYear(year))
//Check For Leap Year
spacerDays = 29;
if(!leapYear(year))
spacerDays = 28;
break;
case 4:
monthDays = 30;
spacerDays = 31;
break;
case 5:
monthDays = 31;
spacerDays = 30;
break;
case 6:
monthDays = 30;
spacerDays = 31;
break;
case 7:
monthDays = 31;
spacerDays = 30;
break;
case 8:
monthDays = 31;
spacerDays = 31;
break;
case 9:
monthDays = 30;
spacerDays = 31;
break;
case 10:
monthDays = 31;
spacerDays = 30;
break;
case 11:
monthDays = 30;
spacerDays = 31;
break;
case 12:
monthDays = 31;
spacerDays = 30;
break;
}
}
//Function 5
//Prints Out All Month Names
void monthNames(int count, int year)
{
switch (count)
{
case 1:
cout << " January " << year << endl;
break;
case 2:
cout << " February " << year << endl;
break;
case 3:
cout << " March " << year << endl;
break;
case 4:
cout << " April " << year << endl;
break;
case 5:
cout << " May " << year << endl;
break;
case 6:
cout << " June " << year << endl;
break;
case 7:
cout << " July " << year << endl;
break;
case 8:
cout << " August " << year << endl;
break;
case 9:
cout << " September " << year << endl;
break;
case 10:
cout << " October " << year << endl;
break;
case 11:
cout << " November " << year << endl;
break;
case 12:
cout << " December " << year << endl;
break;
}
}
//Function 6
//Prints Days And Indents Them Accordingly
void dayNames()
{
cout << " --------------------" << endl;
cout << " S M T W T F S" << endl;
}
//Function 7
//This Prints The Spaces Between Days and Months
void spacer(int start, int count, int& colCount, int& prevSpacer, int& monthDays, int& monthCount, int& spacerDays, int& year)
{
if (count == 1)
{
int loopCount;
for (loopCount = 0; loopCount < start; loopCount++)
{
cout << " ";
prevSpacer++;
}
colCount =+ start;
}
else if (count != 1)
{
int otherSpacer;
int loopCount;
int monthCount = count;
monthNums(monthCount, monthDays, spacerDays);
//Adds Number Of Spaces And Divides By 7
otherSpacer = (prevSpacer + spacerDays) % 7;
prevSpacer = 0;
for (loopCount = 0; loopCount < otherSpacer; loopCount++)
{
cout << " ";
prevSpacer++;
colCount =+ otherSpacer;
}
}
}
//Main Function
int main()
{
int year;
int start;
cout << "Please Enter Year To View The Calender: ";
cin >> year;
while(year <= 0)
{
cout<<"Please Enter A Valid Year (Larger Than 0): ";
cin >> year;
}
cout << endl << "0 - Sunday" << endl << "1 - Monday" << endl << "2 - Tuesday" << endl << "3 - Wednesday" << endl << "4 - Thursday" << endl << "5 - Friday" << endl << "6 - Saturday" << endl << endl;
cout << "Please Enter The Day Of The Week January 1st Falls On (See Above): ";
cin >> start;
cout << endl << endl << endl;
//Check To Make Sure User Entered A Correct Day
while ((start < 0) && (start > 6))
{
cout << endl << endl << endl;
cout << "You Entered An Incorrect Day. Please Enter An Integer Between 0-6.";
cin>>start;
}
printCal(year, start); // Calls The Function So That It Prints The Calender
cout << endl;
system("pause");
return(0);
}
|