I asked this question earlier and it was answered for programming C. Would the answer change if it was for Programming C++ ? Write a function that takes the current date and corrects the number of days, if it's wrong.  The function must return true if the date passed to it is a valid date and false, if not. The main function uses the returned value to either print "Date validated", if a valid date was entered or "Invalid date entered. Changed to ", followed by the modified date. For example: if given 11/31/2020, it will produce 12/1/2020. If given 2/29/2021, it will make it 3/1/2021. But, if 11/29/2020 is entered, it will not change it. To check the date, the function uses the fact that months 4, 6, 9, 11 have 30 days, month 2 has 28 days in non-leap years and 29 in leap years and the remaining months have 31 days. A year is a leap year if it's divisible by 400 or if not, it's divisible by 4, but not 100. Example interaction between the user and the program: Enter a date: 2/31/2021 Invalid date entered. Changed to  3/3/2021 Another example: Enter a date: 12/32/2020 Invalid date entered. Changed to  1/1/2021 Another example: Enter a date:  10/28/2020 Date validated. Press any key to continue

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 1TF: Mark the following statements as true or false: a. To use a predefined function in a program, you...
icon
Related questions
Question

I asked this question earlier and it was answered for programming C. Would the answer change if it was for Programming C++ ?

Write a function that takes the current date and corrects the number of days, if it's wrong.  The function must return true if the date passed to it is a valid date and false, if not. The main function uses the returned value to either print "Date validated", if a valid date was entered or "Invalid date entered. Changed to ", followed by the modified date.

For example: if given 11/31/2020, it will produce 12/1/2020. If given 2/29/2021, it will make it 3/1/2021. But, if 11/29/2020 is entered, it will not change it.

To check the date, the function uses the fact that months 4, 6, 9, 11 have 30 days, month 2 has 28 days in non-leap years and 29 in leap years and the remaining months have 31 days.

A year is a leap year if it's divisible by 400 or if not, it's divisible by 4, but not 100.

Example interaction between the user and the program:

Enter a date: 2/31/2021

Invalid date entered. Changed to  3/3/2021

Another example:

Enter a date: 12/32/2020

Invalid date entered. Changed to  1/1/2021

Another example:

Enter a date:  10/28/2020

Date validated.

Press any key to continue.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Events
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning