372 views
4 votes
In this lab, you add the input and output statements to a partially completed C++ program. When completed, the user should be able to enter a year, a month, and a day. The program then determines if the date is valid. Valid years are those that are greater than 0, valid months include the values 1 through 12, and valid days include the values 1 through 31.

Notice that variables have been declared for you.
Write the simulated housekeeping() function that contains the prompts and input statements to retrieve a year, a month, and a day from the user.
Include the output statements in the simulated endOfJob() function. The format of the output is as follows:

month/day/year is a valid date.
or

month/day/year is an invalid date.
Execute the program by clicking the Run button at the bottom of the screen. Enter the following date:

month = 5, day = 32, year = 2014.
Execute the program entering the following date:

month = 9, day = 21

User Jwilleke
by
8.7k points

1 Answer

2 votes

Answer:

Step-by-step explanation:

Sure, I can help you with that. Here is an example of how you can write the simulated housekeeping() and endOfJob() functions in C++ to retrieve the year, month, and day from the user and determine if the date is valid or not:

c++: ```

#include <iostream>

using namespace std;

int year, month, day;

void housekeeping() {

cout << "Enter the year: ";

cin >> year;

cout << "Enter the month: ";

cin >> month;

cout << "Enter the day: ";

cin >> day;

}

void endOfJob() {

if (year > 0 && month >= 1 && month <= 12 && day >= 1 && day <= 31) {

cout << month << "/" << day << "/" << year << " is a valid date." << endl;

} else {

cout << month << "/" << day << "/" << year << " is an invalid date." << endl;

}

}

int main() {

housekeeping();

endOfJob();

return 0;

} ```

In the above code, the housekeeping() function prompts the user to enter the year, month, and day, and the values are stored in the variables year, month, and day respectively.

The endOfJob() function checks if the year is greater than 0 and if the month and day are within the valid ranges. If all conditions are met, the program outputs that the date is valid. Otherwise, the program outputs that the date is invalid.

Finally, the main() function calls the housekeeping() and endOfJob() functions, and then the program terminates.

To execute the program, you can copy and paste the above code into a C++ compiler, or an online compiler like Ideone, and run it. When prompted, you can enter the following date:

sql: ```

month = 5, day = 32, year = 2014 ```

and the program will output that the date is invalid. Similarly, when prompted, you can enter the following date:

sql: ```

month = 9, day = 21, year = 2022 ```

and the program will output that the date is valid.

Hope this helps, Cheers! :^)

User Eric Fode
by
8.8k points

No related questions found