Create two different implementations of a class called Date. Each implementation
ID: 3668773 • Letter: C
Question
Create two different implementations of a class called Date. Each implementation should provide the following functionalities: two constructors: i. A default constructor that initializes the date to 1/1/1900. ii. A constructor that accepts three arguments: a month (type int), a day (type int) and a year (type int) to initialize the object instance. The constructor assumes that the day value should be from 1 to 31, the month from1 to 12 and the year is between 1900 and 2025. a getMonth, getDay and getYear methods (these are accessor methods). a setMonth, setDay and setYear methods (these are mutator methods). Each of the three methods takes an integer as an argument and assumes that the value provided fall under the correct range. a display method that prints to the standard output the month, day and year separated by forward slashes (/). an == operator that takes another Date object as an argument. The method will return true if the date of the object instance is equal to the Date objects that is sent as an argument, otherwise the method returns false. a. The first implementation (called Date1) should use three member variables—a month (type int), a day (type int) and a year (type int). The interface and the implementation should be in separate files (.h and .cpp respectively). b. The second implementation (called Date2) should use one member variable—a string that stores the month, day and year separated by forward slashes (/). The interface and the implementation should be in separate files (.h and .cpp respectively). The main( ) method should demonstrate the capabilities of both implementations of the Date class. First, main should create an instance of each implementation then should make sure that each member function is working properly
Explanation / Answer
#ifndef _TM_DEFINED struct tm { int tm_sec; /* seconds after the minute - [0,59] */ int tm_min; /* minutes after the hour - [0,59] */ int tm_hour; /* hours since midnight - [0,23] */ int tm_mday; /* day of the month - [1,31] */ int tm_mon; /* months since January - [0,11] */ int tm_year; /* years since 1900 */ int tm_wday; /* days since Sunday - [0,6] */ int tm_yday; /* days since January 1 - [0,365] */ int tm_isdst; /* daylight savings time flag */ }; #define _TM_DEFINED #endif typedef struct _FILETIME { DWORD dwLowDateTime; DWORD dwHighDateTime; } FILETIME, *PFILETIME, *LPFILETIME; // // System time is represented with the following structure: // typedef struct _SYSTEMTIME { WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds; } SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME; class CTime { public: // Constructors static CTime PASCAL GetCurrentTime(); CTime(); CTime(time_t time); CTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, int nDST = -1); CTime(WORD wDosDate, WORD wDosTime, int nDST = -1); CTime(const CTime& timeSrc); CTime(const SYSTEMTIME& sysTime, int nDST = -1); CTime(const FILETIME& fileTime, int nDST = -1); const CTime& operator=(const CTime& timeSrc); const CTime& operator=(time_t t); // Attributes struct tm* GetGmtTm(struct tm* ptm = NULL) const; struct tm* GetLocalTm(struct tm* ptm = NULL) const; BOOL GetAsSystemTime(SYSTEMTIME& timeDest) const; time_t GetTime() const; int GetYear() const; int GetMonth() const; // month of year (1 = Jan) int GetDay() const; // day of month int GetHour() const; int GetMinute() const; int GetSecond() const; int GetDayOfWeek() const; // 1=Sun, 2=Mon, ..., 7=Sat // Operations // time math CTimeSpan operator-(CTime time) const; CTime operator-(CTimeSpan timeSpan) const; CTime operator+(CTimeSpan timeSpan) const; const CTime& operator+=(CTimeSpan timeSpan); const CTime& operator-=(CTimeSpan timeSpan); BOOL operator==(CTime time) const; BOOL operator!=(CTime time) const; BOOL operator(CTime time) const; BOOL operator=(CTime time) const; // formatting using "C" strftime CString Format(LPCTSTR pFormat) const; CString FormatGmt(LPCTSTR pFormat) const; CString Format(UINT nFormatID) const; CString FormatGmt(UINT nFormatID) const; #ifdef _UNICODE // for compatibility with MFC 3.x CString Format(LPCSTR pFormat) const; CString FormatGmt(LPCSTR pFormat) const; #endif // serialization #ifdef _DEBUG friend CDumpContext& AFXAPI operatorRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.