/* CS401: Intro to Comp Sci * summer 2001 * * This program defines a very simple Date class and demonstrates * a few uses of the class. It is not typical to put the class header, * method definitions, and calling function all in one file, but it is * done here for simplicity. */ #include #include #include // the Date header - this allows Date objects to be used in main(). class Date { private: int month, day, year; public: void set(int,int,int); // m,d,y void print(); void read(); }; int main() { Date today, finalDay; today.set(7,11,2001); finalDay.set(8,1,2001); cout << "today is "; today.print(); cout << endl; cout << "the final is on "; finalDay.print(); cout << endl; getch(); } // the method definitions // this sets a Date object to a given date void Date::set(int m, int d, int y) { month = m; day = d; year = y; } // this method displays the Date on the screen void Date::print() { cout << month << '/' << day << '/' << year; } // this reads a Date in from cin void Date::read() { cout << "Enter the month: "; cin >> month; cout << "Enter the day: "; cin >> day; cout << "Enter the year: "; cin >> year; } /* OUTPUT: today is 7/11/2001 the final is on 8/1/2001 */