Write the class definition for a Date class that contains three integer data members: month, day and year. Include a default constructor that assigns the date 1/1/2000 to any new object that does not receive arguments. Also include a function that displays the Date object. Write a main() function in which you instantiate two Date objects – one that you create using the default constructor values, and one that you create using three arguments – and display its values.
#include <iostream>
#include <string>
class Date
{
private:
size_t _day;
size_t _month;
size_t _year;
public:
void displayDate()
{
std::cout << _day << "/" << _month << "/" << _year << std::endl;
}
Date() : _day(1), _month(1), _year(2000) {};
Date(size_t day, size_t month, size_t year) : _day(day), _month(month), _year(year) {};
~Date() {};
};
int main()
{
Date dataDefault;
dataDefault.displayDate();
Date data(2, 2, 2002);
data.displayDate();
return 0;
}
Comments
Leave a comment