Description
In this assignment you are asked to implement a Date class representing a month, day, and year. The following UML class diagram shows all attributes and behaviors for class Date.
DATE
-month: Integer
-day: Integer
-year: Integer
+Date(month: Integer, day: Integer, year: Integer)
+setMonth(month: Integer)
+getMonth(): Integer
+setDay(day: Integer)
+getDay(): Integer
+setYear(year: Integer)
+getYear(): Integer
+display()
Figure 1. UML class diagram for class Date
-
(2 points) Create a class Date that includes three pieces of information as private data members – a month (type int), a day (type int) and a year (type int).
-
(1 point) Provide a public set and a get function for each data member (setMonth, getMonth, setDay, getDay, setYear, getYear).
-
(1 point) Provide a public constructor with three parameters that uses the parameters to initialize the three data members.
-
(2 point) Assume that the values provided for the year and day are always correct, but ensure that the month value provided to the constructor and setMonth is in the range 1-12; if it isn’t, set the month to 1 and output an error message to cerr indicating that there was an attempt to set an invalid month value.
-
(1 point) Provide a member function display that outputs to cout the month, day, and year separated by forward slashes (/) (e.g. “6/4/2011”).
-
(2 points) Write a test program that demonstrates class Date’s capabilities. Your test program should call all of class Date’s public functions.
-
(1 point) Make sure your source code is well-commented, consistently formatted, uses no magic numbers/values, follows a consistent style, and is ANSI-compliant.
Place all source code and a screen capture of the output produced by your program in a single Word or PDF document. Submit this document.