0% found this document useful (0 votes)
82 views2 pages

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

This C++ code defines a dateType class with methods to set, get, print, and check validity of dates. The setDate method sets the day, month, and year member variables, checking the dates are valid. getDate returns the member variables. Additional methods get the individual day, month, and year, print the date, initialize dates on construction, and check for leap years.

Uploaded by

api-346895508
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views2 pages

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

This C++ code defines a dateType class with methods to set, get, print, and check validity of dates. The setDate method sets the day, month, and year member variables, checking the dates are valid. getDate returns the member variables. Additional methods get the individual day, month, and year, print the date, initialize dates on construction, and check for leap years.

Uploaded by

api-346895508
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 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