/* * @topic S-0326-09-01-10 Date class example * @brief class Date declaration */ #ifndef DATE_H_INCLUDED_ #define DATE_H_INCLUDED_ // Online documentation for ctime library functions in this // sample can be found here: // http://pubs.opengroup.org/onlinepubs/009695399/mindex.html #include <ctime> #include <iostream> class Date { friend std::ostream& operator << (std::ostream& ostr, Date dt); private: // data int mm; // month int dd; // day int yyyy; // year public: // constructors Date() { set_current(); } Date( int xmm, int xdd, int xyyyy ) : // constructor initializer list mm( xmm ), dd( xdd ), yyyy( xyyyy ) { //mm = xmm; //dd = xdd; //yyyy = xyyyy; } // operations void print() { std::cout << mm << "/" << dd << "/" << yyyy << "\n"; } void set_current() { time_t now = time(0); // get system time tm tms; tms = *localtime(&now); // convert to date/time components mm = tms.tm_mon + 1; // month is zero based dd = tms.tm_mday; yyyy = tms.tm_year + 1900; // year is since 1900 } };//class Date // Example of overloaded operator: std::ostream& operator << (std::ostream& ostr, Date dt) { ostr << dt.mm << "/" << dt.dd << "/" << dt.yyyy; return ostr; } #endif // DATE_H_INCLUDED_