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
|
string MonthToString(int numMonth)
{
/*
Pre: variable numMonth must be defined
Post: the month name will be calculated and returned
Purpose: determine the month based on input number
*/
//declare variable[s]
string monthName;
// determine month's name based on entered month's digit
if (numMonth == 1)
{
monthName = "January"; //store january as month's name
}
else if (numMonth == 2)
{
monthName = "February"; // store february as month's name
}
else if (numMonth == 3)
{
monthName = "March"; // store march as month's name
}
else if (numMonth == 4)
{
monthName = "April"; //store april as month's name
}
else if (numMonth == 5)
{
monthName = "May"; //store may as month's name
}
else if (numMonth == 6)
{
monthName = "June"; //store june as months's name
}
else if (numMonth == 7)
{
monthName = "July"; //store july as month's name
}
else if (numMonth == 8)
{
monthName = "August"; //store august as month's name
}
else if (numMonth == 9)
{
monthName = "September"; //store september as month's name
}
else if (numMonth == 10)
{
monthName = "October"; // store october as month;s name
}
else if (numMonth == 11)
{
monthName = "November"; // store november as month's name
}
else // use just "else" because every other option is taken,
{ // assuming only valid months are entered
monthName = "December"; // store december as month's name
}
return monthName; // return the name of the month
}
int CalcDays(int numMonth, int date)
{
/*
Pre: variables numMonth and year must be defined
Post: day number of the year will be calculated and returned
Purpose: calculate day number in the year
*/
//declare vriable[s]
int dayOfYear;
//determine the day based on the day and month
if (numMonth == 1)
{
dayOfYear = date;
//for january, the day of the year is just the date entered
}
else if (numMonth == 2)
{
dayOfYear = date + JAN;
//february, the day is equal to the date plus the days from january
}
else if (numMonth == 3)
{
dayOfYear = date + JAN + FEB;
// march, the day is equal to the date plus the days
} // from jan and feb
else if (numMonth == 4)
{
dayOfYear = date + JAN + FEB + MARCH;
//april, day is equal to the date plus the days
} // from jan, feb, march
else if (numMonth == 5)
{
dayOfYear = date + JAN + FEB + MARCH + APRIL;
//may, day is equal to the date plus the
} // days from jan, feb, march...
else if (numMonth == 6)
{
dayOfYear = date + JAN + FEB + MARCH + APRIL + MAY;
//june, day is equal to the date plus
} // plus the days from all preceeding months
else if (numMonth == 7)
{
dayOfYear = date + JAN + FEB + MARCH + APRIL + MAY + JUNE;
// july, day is equal to the date
} // plus the days from all preceeding months
else if (numMonth == 8)
{
dayOfYear = date + JAN + FEB + MARCH + APRIL + MAY + JUNE;
// august, day is equal to thE
} // date plusthe days from all preceeding months
else if (numMonth == 9)
{
dayOfYear = date + JAN + FEB + MARCH + APRIL + MAY + JUNE + JULY + AUG;
// september, day is equal to
} //the date plus all preceeding months
else if (numMonth == 10)
{
dayOfYear = date + JAN + FEB + MARCH + APRIL + MAY + JUNE + JULY + AUG + SEPT;
//october, the day is equal
} // to the date plus all preceeding months
else if (numMonth == 11)
{
dayOfYear = date + JAN + FEB + MARCH + APRIL + MAY + JUNE + JULY + AUG
+ SEPT + OCT;
// november
} // the date is equal to the date plus all preceeding months
else
{
dayOfYear = date + JAN + FEB + MARCH + APRIL + MAY + JUNE + JULY + AUG
+ SEPT + OCT + NOV;
//december
} //the date is equal to the date plus all preceeding months
return dayOfYear; //returns the day of the year to main
}
bool IsLeap(int yearNum)
{
/*
Pre: variable yearNum must be defined
Post: the truth of whether it is a leap year will be determined and returned
Purpose: calculate if year is a leap year
*/
//declare variable[s]
bool leapYear;
// if the year is divisble by 4, 100, or 400
if (yearNum % 4 == 0 || yearNum % 100 == 0 && yearNum % 400 == 0)
{ // it is true it is a leap year
leapYear = true;
}
else
{// if it is not, it is false it is a leap year
leapYear = false;
}
return leapYear; //return true or false
}
void PrintHeading(ofstream& dout, string fileName)
{
dout << "*********************************" << endl;
dout << "* *" << endl;
dout << "* Days Calculation Program *" << endl;
dout << "* File name: " << fileName << " *" << endl;
dout << "* *" << endl;
dout << "*********************************" << endl;
}
bool ValidMonth(int month)
{
bool validMonth; // variable to store is month is valid
if (month > 12 || month < 1)
{
validMonth = false;
}
else
{
validMonth = true;
}
return validMonth;
}
bool ValidDay(int month,int day, bool leapYear)
{
bool validDay;
if (month == 9, 4, 6, 11 && day > 30)
{
validDay = false;
}
else if (month == 2 && day > 28 && leapYear == false)
{
validDay = false;
}
else if (month == 1, 3, 5, 7, 8, 10, 12 && day > 31)
{
validDay = false;
}
else
{
validDay = true;
}
return validDay;
}
|