Question: In C + + write a class called Date that has the following member variables: month : an int data to hold month day :

In C++ write a class called Date that has the following member variables:
month : an int data to hold month
day : an int data to hold day
year : an int data to hold year and it will be 4 digits.
In addition, the class should have the following constructors and member
functions
Constructor : will month to 1, day to 1 and year to 2024
Constructor : an overload of the Constructor above but this time, the
values for month, day and year will be provided. In addition, value for the
month should be validated such that it will have only values from 1 to 12. If
invalid, set month to 1. Also, values for the day should be validated according
to the month. For example, if month is 2 then day should range from 1 to 28.
You can ignore leap years for now.
Accessors (Getters) : appropriate accessor methods for each of
the data members. These methods should be const methods.
Mutators (Setters) : appropriate mutator methods for each of the
data members.
print() : method to print the date in the format mm/dd/yy with yy as
four digits.
You must define the specification in a file called Date.h and the implementation
of constructors and the methods should be another file called Date.cpp
Demonstrate that your class is working by doing the following:
creating a Date object called d1 using the default constructor. Nothing is
supplied.
creating a Date object called d2 by providing values for month, day and
year.
Call the print() method in each object to show that it is working correctly.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!