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

  1. // ex05001.cpp
  2. // The structure as a data type
  3. #include <iostream.h>
  4.  
  5. // ------  structure = data type
  6. struct date {
  7.     int month;
  8.     int day;
  9.     int year;
  10. };
  11.  
  12. main()
  13. {
  14.     static date birthday = {10,12,1962};    // a date
  15.     date dates[10];                            // an array of dates
  16.     date *dp = dates;                        // a pointer to a date
  17.     void display(date);                        // a date parameter
  18.  
  19.     for (int i = 0; i < 10; i++)    {
  20.         *(dp + i) = birthday;
  21.         dates[i].year += i;
  22.         cout << "\nOn ";
  23.         display(dates[i]);
  24.         cout << " Sharon was ";
  25.         if (i > 0)
  26.             cout << i;
  27.         else
  28.             cout << "born";
  29.     }
  30. }
  31.  
  32. void display(date dt)
  33. {
  34.     static char *mon[] = {
  35.         "January","February","March","April","May","June",
  36.         "July","August","September","October","November",
  37.         "December"};
  38.     cout << mon[dt.month-1] << " " << dt.day << ", " 
  39.          << dt.year;
  40. }
  41.