Question: Write a class named DayOfYear that takes an integer representing a day of the year and translates it to a string consisting of the month

Write a class named DayOfYear that takes an integer representing a day of the year and translates it to a string consisting of the month followed by day of the month.

Examples: Day 2 => January 2, Day 32 => February 1, Day 365 => December 31.

Assume 365 days in a year.

The constructor for the class should take as parameter an integer representing the day of the year, and the class should have a member function print() that prints the day in the month-day format like the examples above.

The class should have an integer member variable to represent the day, and should have static member variables of type string to assist in the translation from the integer format to the month-day format.

Test your class by inputting various integers representing days and printing out their representation in the month-day format.

Modify the DayOfYear class, written above to add a constructor that takes two parameters: a string representing month and an integer (1-31) for the day of the month.

The constructor should then initialize the integer member of the class to represent the day specified by the month and day of month parameters.

The constructor should terminate the program with an appropriate error message if the number entered for a day is outside the range of days for the month given. cstdlib has the exit function.

Add the following overloaded operators:

Assignment operator.

++prefix and postfix increment operators. These operators should modify the DayOfYear object so that it represents the next day. If the day is already the end of the year, the new value of the object will represent the first day of the year.

--prefix and postfix decrement operators. These operators should modify the DayOfYear object so that it represents the previous day. If the day is already the first day of the year, the new value of the object will represent the last day of the year.

DayOfYear operator++(); // pre

DayOfYear operator++(int); // post

DayOfYear operator--(); // pre

DayOfYear operator--(int); // post

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!