Description
The purpose of this challenge is to use arrays, function parameters passed by reference.
Requirements
- Ask the user to enter three different values to represent month, day and year. See the sample interaction.
- Ask the user to enter another value, int days
- Write a function called next_day(int month, int day, int year, int & nextm, int & nextd, int & nexty). The first 3 parameters of this function represent a date. Use this function to determine the next day following this date. Use the 3 pass-by-reference nextm, nextd and nexty parameters to store the appropriate values for the next day.
- This function does not return anything, but it does determine what the next month, day and year are and these are “returned” in the last three parameters.
- In this function, create an array to contain the number of days in each month. The array should have 12 entries, one for each month. This array will be used to detect when the next day(s) will be in subsequent month(s).
- Make sure the next_day function handles leap years, as well as dates that cross month and year boundaries (see interaction)
- Make sure that your next_day function does not have any cout and cin calls.
- In main, use the value from step 2 to display the next following days. See the sample interaction.
- HINT: The first 3 params of the next_day() function act like inputs, and the last 3 params act like outputs of the function.
- When you are testing, make sure to test:
- A series of days within a month, without crossing over into the next month, something like : Start at 2/2/2026 and show the next 10 days
- A series of days crossing over into a new month, something like : Start at 3/24/2026 and show the next 14 days. To test leap years, pick a date late in February of a leap year like 2024
- A series of days crossing over into a new year, something like : Start at 12/30/2025 and show the next 9 days
- To really test it, enter a number of days that span more than a month or two, to make sure that the days will correctly flow into the subsequent months.
Sample/partial main()
int main()
{
int month, int day, int year;
int days;
// use a loop counting up to days, showing the next days
// by calling the next_day() function
return 0;
}
Sample Interaction / Output
Enter month, day, year: 2 28 2024 Enter count of following days: 10 2-29-2024 3-1-2024 3-2-2024 3-3-2024 3-4-2024 3-5-2024 3-6-2024 3-7-2024 3-8-2024 3-9-2024 ANOTHER TEST RUN: Enter month, day, year: 12 28 2023 Enter count of following days: 7 12-29-2023 12-30-2023 12-31-2023 1-1-2024 1-2-2024 1-3-2024 1-4-2024
LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT
CATALOG ID: CPP-CHAL0006f
Print Requirements
