You are provided with a class definition for a class called Date, used to store calendar dates (see below). Certain functionality for output and equality testing has already been provided for you. Write implementations for the two constructors and the other four member functions which are declared but not implemented.
Can someone explain how to being coding the other constructors? What needs a constructor in this line of code?
Also what are the four member functions that need to be declared?
#include <iostream>
usingnamespace std;
class Date {
int year;
int month;
int day;
public:
Date() {year=2000; month=1; day=1;}
Date(int y, int m, int d);
bool is_valid(); // Does the Date object represent a real date (year, month, day assignment)?
bool is_leapyear(); // Is the year a leap year?
Date next(); // Returns a new Date object representing the next day.
int days_until(Date other); // a.days_until(b) returns the amount of time in days between a and b.
booloperator==(Date right) {
return ((year == right.year) && (month == right.month) && (day == right.day));
}
friend ostream& operator<<(ostream& out, Date d);
};
ostream& operator<<(ostream& out, Date d) {
out << d.month << "/" << d.day << "/" << d.year;
}
int main() {
// Test Code: uncomment as you implement your member functions.
/*
Date today(2014, 5, 31);
cout << "\"Today\" is " << today << endl;
cout << "\"Tomorrow\" is " << today.next() << endl;
int m, d, y;
cout << "Enter Birthday (MM DD YYYY): ";
cin >> m >> d >> y;
Date birthday(y, m, d);
cout << "You were born ";
cout << birthday.days_until(today);
cout << " days ago." << endl;
*/
}
I appreciate you reading this and offering any insight! Have a nice day!