home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / ANSICPP.ZIP / EX07027.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-24  |  753 b   |  40 lines

  1. // ex07027.cpp
  2. // using public static members without objects
  3. #include <iostream.h>
  4.  
  5. class Date {
  6.     int mo, da, yr;
  7. public:
  8.     static int format;    // 1 = mm/dd/yy, 2 = dd/mm/yy
  9.     Date(int m , int d, int y) { mo = m; da = d; yr = y; }
  10.     void display();
  11. };
  12.  
  13. int Date::format;
  14.  
  15. void Date::display()
  16. {
  17.     if (format == 1)
  18.         cout << mo << '/' << da;
  19.     else
  20.         cout << da << '/' << mo;
  21.     cout << '/' << yr;
  22. }
  23.  
  24. main()
  25. {
  26.     char ch = '0';
  27.     while (ch != '3')    {
  28.         cout << "\n  1 = mm/dd/yy";
  29.         cout << "\n  2 = dd/mm/yy";
  30.         cout << "\n  3 = quit\n  ";
  31.         cin >> ch;
  32.         if (ch == '1' || ch == '2')    {
  33.             Date::format = ch - '0'; // no Date declared yet
  34.             // ---- declare and display a date
  35.             Date dt(6, 24, 40);
  36.             dt.display();
  37.         }
  38.     }
  39. }
  40.