#include #include #include //for the functions time and localtime using namespace std; struct date { int year; int month; //in the range 1 to 12 inclusive int day; //in the range 1 to 31 inclusive }; const int date_length[] { 0, //dummy, so that January will have subscript 1 31, //January 28, //February. Pretend there are no leap years. 31, //March 30, //April 31, //May 30, //June 31, //July 31, //August 30, //September 31, //October 30, //November 31 //December }; //Function declarations. void print(const date *p); void next(date *p, int n); void next(date *p); int main() { const date independenceDay {1776, 7, 4}; print(&independenceDay); cout << " is Independence Day.\n"; //Ask the operating system for the current date and time. const time_t t {time(nullptr)}; const tm *const p {localtime(&t)}; //Output today's date. const date today {p->tm_year + 1900, p->tm_mon + 1, p->tm_mday}; print(&today); cout << " is today.\n"; //Output tomorrow's date. date tomorrow {today}; next(&tomorrow); //Advance one day. print(&tomorrow); cout << " is tomorrow.\n"; //Output the date of next Christmas, 329 days from today (Jan 30 2025). date christmas {today}; next(&christmas, 329); print(&christmas); cout << " is next Christmas.\n"; return EXIT_SUCCESS; } void print(const date *p) //Can't change the date struct. { cout << p->month << "/" << p->day << "/" << p->year; } void next(date *p, int n) //Can change the date struct. { for (int i {0}; i < n; ++i) { next(p); //Call the other next function, the one with 1 argument } } void next(date *p) //Move this date one day into the future. { if (p->day < date_length[p->month]) { ++p->day; //increments p->day, not p } else { p->day = 1; //Advance into the next month. if (p->month < 12) { ++p->month; } else { p->month = 1; //Advance into the next year. ++p->year; } } }