Here is my code I am working and I cant for life of me get it to print if the year entered is a leap year or not. Please help me fix this.
#include <iostream>
using namespace std;
class dateType
{
private:
int dMonth;
int dDay;
int dYear;
public:
void setDate (int month,int day,int year);
int getDay() const;
int getMonth() const;
int getYear() const;
void printDate() const;
bool isLeapYear (int year);
dateType (int month=0, int day=0, int year=0);
};
void dateType::setDate (int month, int day, int year)
{
if (year<=2008)
{
dYear=year;
if (month<=12)
{
dMonth=month;
switch (month)
{
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(dYear))
{
if (1 <= day && day <= 29)
dDay = day;
else
dDay = 1;
}
else
{
if (1 <= day && day <= 28)
dDay = day;
else
dDay = 1;
}
}
}
}
}
bool dateType::isLeapYear()const
{
if ((dYear % 4 == 0 && dYear % 100 != 0) || (dYear % 400 == 0))
return true;
else
return false;
}
void dateType::printDate() const
{
cout << dMonth << "-" << dDay << "-" << dYear;
}
int dateType::getMonth() const
{
return dMonth;
}
int dateType::getDay() const
{
return dDay;
}
int dateType::getYear() const
{
return dYear;
}
dateType::dateType (int month, int day, int year)
{
dMonth=month;
dDay=day;
dYear=year;
}
void main()
{
int m, d, y;
dateType date (0,0,0);
cout<<"Enter the Month: ";
cin>>m;
cout<<"Enter the Day: ";
cin>>d;
cout<<"Enter the Year: ";
cin>>y;
date.setDate(m, d, y);
bool check= date.isLeapYear (y);
if (check)
cout<<"Leap Year: ";
date.printDate();
system ("pause");
}