home *** CD-ROM | disk | FTP | other *** search
- // ex05001.cpp
- // The structure as a data type
- #include <iostream.h>
-
- // ------ structure = data type
- struct date {
- int month;
- int day;
- int year;
- };
-
- main()
- {
- static date birthday = {10,12,1962}; // a date
- date dates[10]; // an array of dates
- date *dp = dates; // a pointer to a date
- void display(date); // a date parameter
-
- for (int i = 0; i < 10; i++) {
- *(dp + i) = birthday;
- dates[i].year += i;
- cout << "\nOn ";
- display(dates[i]);
- cout << " Sharon was ";
- if (i > 0)
- cout << i;
- else
- cout << "born";
- }
- }
-
- void display(date dt)
- {
- static char *mon[] = {
- "January","February","March","April","May","June",
- "July","August","September","October","November",
- "December"};
- cout << mon[dt.month-1] << " " << dt.day << ", "
- << dt.year;
- }