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
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
void getCalendarInput (/*inout*/ int&); // gets user input of year
bool isLeapYear (/*in*/ int); // check and return truth value for leap year
int startDayInputYear (/*in*/ int ); // computes start day for input year
int numOfDaysInMonth (/*in*/ int,/*in*/ bool); // returns number of days in month
void CalendarMonthHeader (/*in*/ int); // prints header for each month
void printMonth (/*in*/int,/*in*/ int&); // prints month days and sends out the first day of the next month
void whitespace (/*in*/int); // prints the specified amount of spaces or leading white spaces
int main()
{
int year, month;
getCalendarInput(year);
CalendarMonthHeader(month);
return 0;
}
void getCalendarInput (/*inout*/ int& year)
{
int monthDays[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int DaysNumWeek;
int firstDayInCurrentMonth;
int currentMonth = 1;
int numDays, month;
bool leap;
string str; //maybe needed for input validation
char choice;
//prompt for input
cout << "What year do you want a calendar for? ";
cin >>year; // str?
while(year < 0 || !cin)
{
cin.clear();
cin.ignore(200, '\n');
cout << "Invalid integer! Enter a value greater than 0!\n" << endl;
cout << "What year do you want a calendar for? ";
cin >>year;
}
CalendarMonthHeader(month);
/* leap = isLeapYear(year); //function call returns bool truth value
//needed to determine number of days in month for leap and non leap year
firstDayInCurrentMonth = startDayInputYear( year ); // function call returns start day.
// Days of week numbered 0 through 9 for Sunday through Saturday.
cout<< year << " " << leap << " " << firstDayInCurrentMonth <<endl; //remove statement - used to test key variable values */
}
bool isLeapYear (/*in*/ int year)
{
return ((year%4==0) && (year%100 !=0))||(year%400==0);
}
int startDayInputYear (/*in*/ int year)
{
int startday;
int num1, num2, num3;
num1 = (year - 1)/ 4;
num2 = (year - 1)/ 100;
num3 = (year - 1)/ 400;
startday = (year + num1 - num2 + num3) %7;
return startday;
}
int numOfDaysInMonth (/*in*/ int month,/*in*/ bool isLeapYear)
{
int monthDays[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(isLeapYear)
monthDays[1] = 29;
return monthDays[month];
}
void CalendarMonthHeader (/*in*/ int month)
{
int year;
int DaysNumWeek, day;
int monthDays[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
isLeapYear(year);
for(month = 0; month < 12; ++month)
{
if(month == 0)
{
cout << "January \n";
}
if(month == 1)
{
cout << "February \n";
numOfDaysInMonth(month,isLeapYear);
}
if(month == 2)
{
cout << "March \n";
}
if(month == 3)
{
cout << "April \n";
}
if(month == 4)
{
cout << "May \n";
}
if(month == 5)
{
cout << "June \n";
}
if(month == 6)
{
cout << "July \n";
}
if(month == 7)
{
cout << "August \n";
}
if(month == 8)
{
cout << "September \n";
}
if(month == 9)
{
cout << "October \n";
}
if(month == 10)
{
cout << "November \n";
}
if(month == 11)
{
cout << "December \n";
}
}
whitespace(day);
for (int mday = 0; mday < monthDays[month]; ++mday)
{
cout << setw(3) << mday + 1;
DaysNumWeek++;
if (DaysNumWeek == 7)
{
cout << "\n" << setw(3);
DaysNumWeek = 0;
}
}
}
void printMonth (/*in*/int, /*in*/ int&)
{
}
void whitespace (/*in*/int day)
{
for (int i = 0; i < day; i++)
{
cout << " ";
}
}
|