/********************************************* Compared to increment_date.cpp, this code also shows how to write functions to: - allow the user to enter data for an object - print out an object. - make a SHALLOW copy of an object. *********************************************/ #include // note that the structure date is defined in // the header file. #include "increment_date2.h" #include struct date increment_date(struct date d1) { struct date result; result.day = d1.day; result.month = d1.month; result.year = d1.year; result.day++; switch(result.month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: if (result.day == 32) { result.day = 1; result.month++; } break; case 2: if (result.day == 29) { result.day = 1; result.month++; } break; default: if (result.day == 30) { result.day = 1; result.month++; } } if (result.month == 13) { result.month = 1; result.year++; } return result; } struct date input_date() { struct date result; printf("please enter month day year:\n"); scanf("%d %d %d", &(result.month), &(result.day), &(result.year)); return result; } void print_date(char * name, struct date d1) { printf("%s = %d/%d/%d\n", name, d1.month, d1.day, d1.year); } struct date copy_date(struct date input) { struct date result = input; return result; } int main(void) { /* date 1 */ struct date d1 = input_date(); struct date d2 = increment_date(d1); print_date("d1", d1); print_date("d2", d2); }