Create and augment a Date class.
// constructor definition
#include "Date.h"
Date::Date ()
{
month = day = year = 1;
}
Date::Date (int mn, int dy, int yr)
{
static int length[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
month = max(1, mn);
month = min(month,12);
day = max(1,dy);
day = min(day, length[month]);
year = max(1, yr);
}
void Date::display()
{
static string name[] = {"nothing", "January", "February", "March", "April",
"May", "June", "July", "August", "September", "October",
"November", "December" };
cout << '\n' << name[month] << ' ' << day << "," << year << '\n';
cout << "Days so far: " << DaysSoFar() << '\n';
}
int Date::DaysSoFar()
{
int total = 0;
static int length[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
for (int i=1; i < month; i++) total += length[i];
total += day;
return (total);
}
int Date::GetMonth()
{
return month;
}
void Date::SetMonth(int mn)
{
month = max(1, mn);
month = min(month, 12);
}
#include <iostream>
#include "Date.h"
using namespace std;
int main()
{
Date mydate(1, 2, 1993);
Date date2(4,11,2018);
Date date3;
Date date4(34,25,2034);
mydate.display();
date2.display();
date3.display();
date4.display();
}