Homework #1 – Class Date solution


5/5 - (2 votes)

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.
Figure 1. UML class diagram for class Date
1. (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). 2. (1 point) Provide a public set and a get function for each data member (setMonth, getMonth, setDay, getDay, setYear, getYear). 3. (1 point) Provide a public constructor with three parameters that uses the parameters to initialize the three data members. 4. (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. 5. (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”). 6. (2 points) Write a test program that demonstrates class Date’s capabilities. Your test program should call all of class Date’s public functions. 7. (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.

Open chat
Chat now
Hello there
Click below to chat with us