Assign
Assign
REQUIREMENTS:
Problem Description:
else
{
}
day = d;
}
void Date::setMonth(int m)
{
if (!(Date::isValidMonth(m)))
{
cout << "The month is invalid." << endl;
}
else
{
month = m;
}
}
void Date::setYear(int y)
{
if (!(Date::isValidYear(y)))
{
cout << "The year is invalid." << endl;
}
else
{
year = y;
}
}
void Date::getDateA()
{
if (validDate() == true)
{
cout << month << "/" << day << "/" << year << endl;
}
else
{
cout << "The date is invalid." << endl;
}
}
void Date::getDateB()
{
if (validDate() == true)
{
string name[] = {"January", "February", "March", "April",
"May", "June", "July", "August", "September", "October", "November",
"December"};
cout << name[month - 1] << " " << day << ", " << year << endl;
//we use month - 1 because the array name starts at 0
}
else
{
}
void Date::getDateC()
{
if (validDate() == true)
{
string name[] = {"January", "February", "March", "April",
"May", "June", "July", "August", "September", "October", "November",
"December"}; //see getDateB for why we need this
cout << day << " " << name[month - 1] << ", " << year << endl;
}
else
{
cout << "The date is invalid." << endl;
}
}
bool Date::validDate()
if (month >= 1 && month <= 12 && day >= 1 && day <= 30 && year >= 1900
&& year <= 2025)
{
return true;
}
else
{
return false;
}
}
static bool Date::isValidYear(int y)
{
if (y < 1900 || y > 2016)
{
return false;
}
}
static bool Date::isValidMonth(int m)
{
if(m<1||m>12)
{
return false;
}
}
static bool Date::isValidDay(int m,int d)
{
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
{
if(d<1||d>31)
return false;
}
if(m==2)
{
if(isLeapYear()==true)
{
if(d<1||d>29)
return false;
}
else
{
if(d<1||d>28)
return false;
}
}
if(m==4||m==6||m==9||m==11)
{
If(d<1||d>30)
return false;
}
return true;
}
static bool Date::isLeapYear(int y)
{
if(y%4==0)
return true;
return false;
}
int main()
{
int x;
Date();
cout << "Default Date Example: " << endl;
testdate.getDateA(); //test format A
testdate.getDateB(); //test format B
testdate.getDateC(); //test format C
cout << "Invalid Date Example: " << endl;
Date invaliddate(13, 33, 2060);
invaliddate.getDateA();
invaliddate.getDateB();
invaliddate.getDateC();
cin >> x;
return 0;