#include #include using namespace std; const int date_length[] = { 0, //dummy element so that January will have subscript 1 31, //January 28, //February, ignoring for now the possibility of leap year 31, //March 30, //April 31, //May 30, //June 31, //July 31, //August 30, //September 31, //October 30, //November 31 //December }; void date_next(int *pyear, int *pmonth, int *pday, int count); void date_next(int *pyear, int *pmonth, int *pday); void date_print(const int *pyear, const int *pmonth, const int *pday); int main() { int year = 2014; int month = 1; //1 to 12 inclusive int day = 1; //1 to date_length[month] inclusive cout << "How many days forward from "; date_print(&year, &month, &day); cout << " do you want to go? "; int count; //uninitialized variable cin >> count; date_next(&year, &month, &day, count); cout << "The new date is "; date_print(&year, &month, &day); cout << ".\n"; return EXIT_SUCCESS; } void date_next(int *pyear, int *pmonth, int *pday, int count) { //Call the three-argument date_next (line 55) count times. //Pass along the three pointers we received. while (--count >= 0) { date_next(pyear, pmonth, pday); } } void date_next(int *pyear, int *pmonth, int *pday) { //Move to the next date. if (++*pday > date_length[*pmonth]) { *pday = 1; if (++*pmonth > 12) { *pmonth = 1; ++*pyear; } } } void date_print(const int *pyear, const int *pmonth, const int *pday) { cout << *pmonth << "/" << *pday << "/" << *pyear; }