Question: in c + + Design and implement a Date class based on the UML diagram below, subject to the following restrictions and suggestions. - Each
in c Design and implement a Date class based on the UML diagram below,
subject to the following restrictions and suggestions. Each Date must be stored as a single integer equal to the number of days since the fixed base date, January or some other date if you prefer Call that data member mDayssinceBaseDate.
The base year should be stored as a static int data member eg or
The class has a constructor and a set function that have month, day, year parameters. These three values must be used to compute the number of days from the base date to the given date. We have specified a private member function named ymddsbd to do that calculation for both.
The tostring function returns a representation of the stored date in some standard string format that is suitable for display eg yyyymmdd This involves reversing the computation used in the ymddsbd function described above. We have specified a private member function named getymD to do that calculation. We have also suggested a parameter for the tostring function bool brief to provide a choice of date formats.
We have specified some static utility functions eg leapyear that are static because they do not affect the state of any Date objects.
Make sure you use the correct rule for determining whether a given year is a leap year!
Create a file named date.h to store your class definition. Create a file named date.opp that contains the definitions of all the functions declared in date.h
Write client code to test your Date class thoroughly.
Your class should handle "invalid" dates in a reasonable way eg year earlier than the base year, month or day out of range, etc.
Here is the code for setromoday that makes use of the system clock to determine today's date. You need to #include from the C Standard Library to use this code.
void Date::setToToday
struct tm tp ;
timet now;
now time;
tp localtime&now;
set tptmyear, tptmmon, tptmmday;
getmeekDay function returns the name of the week day corresponding to the stored date. Use this in the fancy version of tostring Hint: Jan was a Monday.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
