Question: Design a class called Date. The class should store a date in three integers: month, day, and year. There should be member functions to print

Design a class called Date.

The class should store a date in three integers: month, day, and year. There should be member functions to print the data in the following forms:

12/25/2017

December 25, 2017

25 December 2017

Demonstrate the class by writing a complete program implementing it.

Input Validation: Do not accept values for the day greater than 31 or less than 1 for month: January, March, May, July, August, October, December. Do not accept values for the day greater than 30 or less than 1 for month: April, June, September, November. Do not accept values for the days greater than 29 for February if it is a leap year. Do not accept values for the days greater than 28 if it is not a leap year. Do not accept values for the month greater than 12 or less than 1.

In general, terms the algorithm for calculating a leap year is as follows...

A year will be a leap year if it is divisible by 4 but not by 100. If a year is divisible by 4 and by 100, it is not a leap year unless it is also divisible by 400.

Thus, years such as 1996, 1992, 1988 and so on are leap years because they are divisible by 4 but not by 100. For century years, the 400 rule is important. Thus, century years 1900, 1800 and 1700 while all still divisible by 4 are also exactly divisible by 100. As they are not further divisible by 400, they are not leap years.

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 Databases Questions!