"Datetype.H": #Include #Include #Include #Include

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 2

//Implementation file date

#include <iostream> //utilized to instate basic I/O functionality.


#include <string> //implemented to utilize string datatype.
#include <iomanip> //Required to use various useful manipulators.
#include "dateType.h" //references external header file.

//standard library
using namespace std; //allows the use of cout & endl without 'std::' prefix.

void dateType::setDate(int month, int day, int year){


if (year >= 1)
dYear = year;
else
dYear = 1900;

if (1 <= month && month <= 12)


dMonth = month;
else
dMonth = 1;

switch (dMonth)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if (1 <= day && day <= 31)
dDay = day;
else
dDay = 1;
break;
case 4:
case 6:
case 9:
case 11:
if (1 <= day && day <= 30)
dDay = day;
else
dDay = 1;
break;
case 2:
if (isLeapYear())
{
if (1 <= day && day <= 29)
dDay = day;
else
dDay = 1;
}
else
{
if (1 <= day && day <= 28)
dDay = day;
else
dDay = 1;
}
}
}

void dateType::getDate(int &month, int &day, int &year){


month = dMonth;
day = dDay;
year = dYear;
}

int dateType::getDay() const{


return dDay;
}

int dateType::getMonth() const {


return dMonth;
}

int dateType::getYear() const {


return dYear;
}

void dateType::printDate() const{


cout << "\n\t" << dMonth << "-" << dDay << "-" << dYear;
}

//constructor
dateType::dateType(int month, int day, int year)
{
setDate(month, day, year);
}

bool dateType::isLeapYear()
{

if (((dYear % 4 == 0) && (dYear % 100 != 0)) || dYear % 400 == 0)


return true;
else
return false;
}

You might also like