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 254
|
#include <iostream>
#include "dateType.h"
using namespace std;
void dateType::setDate(int month, int day, int year)
{
int maxDays = 0;
if (year > 1699 && year < 4000)
{
dYear = year;
}
else
dYear = 2014;
if (month > 0 && month < 13)
{
dMonth = month;
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
maxDays = 31;
break;
case 4:
case 6:
case 9:
case 11:
maxDays = 30;
break;
case 2:
{
if (isLeapYear(year) == true)
maxDays = 29;
else
maxDays = 28;
break;
}
default:
dDay = 31;
}
}
if (day < 1 || day > maxDays)
dDay = 1;
else
dDay = day;
cout << "The Maximum days in the month are: " << maxDays << endl;
}
int dateType::getDay() const
{
return dDay;
}
int dateType::getMonth() const
{
return dMonth;
}
int dateType::getYear() const
{
return dYear;
}
bool dateType::isLeapYear(int year)
{
if (year % 4 != 0) {
return false;
}
else if (year % 400 == 0) {
return true;
}
else if (year % 100 == 0) {
return false;
}
else {
return true;
}
}
void dateType::printDate() const
{
cout << "The date you entered is:" << endl;
cout << dMonth << "/" << dDay << "/" << dYear << endl;
}
dateType::dateType(int month, int day, int year)
{
setDate(month, day, year);
}
void dateType::dayspassed()
{
//PEMDAS
int maxDays = 0, maximumDays = 365, jan = 31, feb = 28, mar = 31, apr = 30, may = 31, jun = 30, jul = 31, aug = 31, sept = 30, oct = 31, nov = 30, dec = 31;
int month = dMonth, year = dYear, days = dDay, passed = 0;
if (isLeapYear(year) == true)
{ feb = 29;
}
else
{ feb = 28;
}
switch (month)
{
case 1:
{
passed = days;
}
case 2:
{
passed = jan + days;
}
case 3:
{
passed = jan + feb + days;
}
case 4:
{
passed = jan + feb + mar + days;
}
case 5:
{
passed = jan + feb + mar + apr + days;
}
case 6:
{
passed = jan + feb + mar + apr + may + days;
}
case 7:
{
passed = jan + feb + mar + apr + may + jun + days;
}
case 8:
{
passed = jan + feb + mar + apr + may + jun + jul + days;
}
case 9:
{
passed = jan + feb + mar + apr + may + jun + jul + aug + days;
}
case 10:
{
passed = jan + feb + mar + apr + may + jun + jul + aug + sept + days;
}
case 11:
{
passed = jan + feb + mar + apr + may + jun + jul + aug + sept + oct + days;
}
case 12:
{
passed = jan + feb + mar + apr + may + jun + jul + aug + sept + oct + nov + days;
}
default:
month = 0;
}
cout << passed << " Days have passed" << endl;
}
void dateType::daysleft()
{
int maxDays = 0, maximumDays = 365, jan = 31, feb = 28, mar = 31, apr = 30, may = 31, jun = 30, jul = 31, aug = 31, sept = 30, oct = 31, nov = 30, dec = 31;
int month = dMonth, year = dYear, days = dDay, left = 0;
if (isLeapYear(year) == true)
{
feb = 29;
}
else
{
feb = 28;
}
switch (month)
{
case 1:
{
left = jan + feb + mar + apr + may + jun + jul + aug + sept + oct + nov + dec + days;
}
case 2:
{
left = feb + mar + apr + may + jun + jul + aug + sept + oct + nov + dec + days;
}
case 3:
{
left = mar + apr + may + jun + jul + aug + sept + oct + nov + dec + days;
}
case 4:
{
left = apr + may + jun + jul + aug + sept + oct + nov + dec + days;
}
case 5:
{
left = may + jun + jul + aug + sept + oct + nov + dec + days;
}
case 6:
{
left = jun + jul + aug + sept + oct + nov + dec + days;
}
case 7:
{
left = jul + aug + sept + oct + nov + dec + days;
}
case 8:
{
left = aug + sept + oct + nov + dec + days;
}
case 9:
{
left = sept + oct + nov + dec + days;
}
case 10:
{
left = oct + nov + dec + days;
}
case 11:
{
left = nov + dec + days;
}
case 12:
{
left = dec + days;
}
default:
month = 0;
}
cout << "There are " << left << " Days Left" << endl;
}
|