Design and implement a class dayType that implements the day of the week in a program. The classdayType should store the day, such as Sun for Sunday. The program should be able to perform thefollowing operations on an object of type dayType:
a)
Set the day.
b)
Print the day.
c)
Return the day.
d)
Return the next day.
e)
Return the previous day.
f)
Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add 4 days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.
g)
Add the appropriate constructors.
The class dateType was designed to implement the date in a program, but the member function setDate
and the constructor do not check whether the date is valid before storing the date in the member variables.
Rewrite the definitions of the function setDate and the constructor so that the values for the month, day,
and year are checked before storing the date into the member variables. Add a member function,
isLeapYear, to check whether a year is a leap year. Moreover, write a test program to test your class.
As you can see the class dateType is designed and implemented to keep track of a date, but it has very
limited operations. Redefine the class dateType so that it can perform the following operations on a date,
in addition to the operations already defined:
a. Set the month.
b. Set the day.
c. Set the year.
d. Return the month.
e. Return the day.
f. Return the year.
g. Test whether the year is a leap year.
h. Return the number of days in the month.
For example, if the date is 3-12-2013, the number of days to
be returned is 31 because there are 31 days in March.
i. Return the number of days passed in the year. For example, if the date is 3-18-2013, the number of days
passed in the year is 77. Note that the number of days returned also includes the current day.
j. Return the number of days remaining in the year. For example, if the date is 3-18-2013, the number of
days remaining in the year is 288.
k. Calculate the new date by adding a fixed number of days to the date.
For example, if the date is 3-18-
2013 and the days to be added are 25, the new date is 4-12-2013.
The class dateType defined prints the date in numerical form. Some applications might require the date to
be printed in another form, such as March 24, 2013. Derive the class extDateType so that the date can be
printed in either form. Add a member variable to the class extDateType so that the month can also be
stored in string form. Add a member function to output the month in the string format, followed by the
year—for example, in the form March 2013.
Write the definitions of the functions to implement the operations for the class extDateType.
Using the classes extDateType and dateType, design the class calendarType so that, given the month and
the year, we can print the calendar for that month. To print a monthly calendar, you must know the first
day of the month and the number of days in that month. Thus, you must store the first day of the month,
which is of the form dayType, and the month and the year of the calendar. Clearly, the month and the year
can be stored in an object of the form extDateType by setting the day component of the date to 1 and
themonth and year as specified by the user. Thus, the class calendarType has two member variables: an
object of the type dayType and an object of the type extDateType.
Design the class calendarType so that the program can print a calendar for any month starting January 1,
1500. Note that the day for January 1 of the year 1500 is a Monday. To calculate the first day of a month,
you can add the appropriate days to Monday of January 1, 1500.
For the class calendarType, include the following operations:
a. Determine the first day of the month for which the calendar will be printed. Call this operation
firstDayOfMonth.
b. Set the month.
c. Set the year.
d. Return the month.
e. Return the year.
f. Print the calendar for the particular month.
g. Add the appropriate constructors to initialize the member variables.
h. Write the definitions of the member functions of the class calendarType to implement the
operations of the class calendarType.