home *** CD-ROM | disk | FTP | other *** search
- // ex07027.cpp
- // using public static members without objects
- #include <iostream.h>
-
- class Date {
- int mo, da, yr;
- public:
- static int format; // 1 = mm/dd/yy, 2 = dd/mm/yy
- Date(int m , int d, int y) { mo = m; da = d; yr = y; }
- void display();
- };
-
- int Date::format;
-
- void Date::display()
- {
- if (format == 1)
- cout << mo << '/' << da;
- else
- cout << da << '/' << mo;
- cout << '/' << yr;
- }
-
- main()
- {
- char ch = '0';
- while (ch != '3') {
- cout << "\n 1 = mm/dd/yy";
- cout << "\n 2 = dd/mm/yy";
- cout << "\n 3 = quit\n ";
- cin >> ch;
- if (ch == '1' || ch == '2') {
- Date::format = ch - '0'; // no Date declared yet
- // ---- declare and display a date
- Date dt(6, 24, 40);
- dt.display();
- }
- }
- }