#include #include // class declaration class Date { private: int month, day, year; public: Date(int = 7, int = 4, int = 2001); // constructor Date(long); // type conversion constructor void showdate(); }; // implementation section // constructor Date::Date(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; } // type conversion constructor from long to date Date::Date(long findate) { year = int(findate/10000.0); month = int((findate - year * 10000.0)/100.0); day = int(findate - year * 10000.0 - month * 100.0); } // member function to display a date void Date::showdate() { cout << setfill('0') << setw(2) << month << '/' << setw(2) << day << '/' << setw(2) << year % 100; return; } int main() { Date a, b(20011225L), c(4,1,1999); // declare 3 objects - initialize 2 of them cout << "Dates a, b, and c are "; a.showdate(); cout << ", "; b.showdate(); cout << ", and "; c.showdate(); cout << ".\n"; a = Date(20020103L); // cast a long to a date cout << "Date a is now "; a.showdate(); cout << ".\n"; return 0; }