#include #include #include //for the functions time and localtime using namespace std; 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 date_print(const int *pyear, const int *pmonth, const int *pday); void date_next(int *pyear, int *pmonth, int *pday, int n); void date_next(int *pyear, int *pmonth, int *pday); int main() { const int independenceDayYear {1776}; //July 4, 1776 const int independenceDayMonth {7}; const int independenceDayDay {4}; date_print(&independenceDayYear, &independenceDayMonth, &independenceDayDay); 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 int todayYear {p->tm_year + 1900}; const int todayMonth {p->tm_mon + 1}; const int todayDay {p->tm_mday}; date_print(&todayYear, &todayMonth, &todayDay); cout << " is today.\n"; //Output tomorrow's date. int tomorrowYear {todayYear}; int tomorrowMonth {todayMonth}; int tomorrowDay {todayDay}; date_next(&tomorrowYear, &tomorrowMonth, &tomorrowDay); //Advance one day. date_print(&tomorrowYear, &tomorrowMonth, &tomorrowDay); cout << " is tomorrow.\n"; //Output the date of next Christmas, 329 days from today (Jan 30 2025). int christmasYear {todayYear}; int christmasMonth {todayMonth}; int christmasDay {todayDay}; date_next(&christmasYear, &christmasMonth, &christmasDay, 329); date_print(&christmasYear, &christmasMonth, &christmasDay); cout << " is next Christmas.\n"; return EXIT_SUCCESS; } void date_print(const int *pyear, const int *pmonth, const int *pday) { cout << *pmonth << "/" << *pday << "/" << *pyear; } void date_next(int *pyear, int *pmonth, int *pday, int n) { for (int i {0}; i < n; ++i) { //Call the other next function, the one with 1 argument date_next(pyear, pmonth, pday); } } void date_next(int *pyear, int *pmonth, int *pday) { if (*pday < date_length[*pmonth]) { ++*pday; //Increments *pday, not p } else { *pday = 1; //Advance into the next month. if (*pmonth < 12) { ++*pmonth; } else { *pmonth = 1; //Advance into the next year. ++*pyear; } } }