Question: For this assignment you will be writing a diagnostic program that will be able to tell a user whether a date is valid. The program

For this assignment you will be writing a "diagnostic" program that will be able to tell a user whether a date is valid. The program should begin by asking the user to supply a date in the following format: YYYYMMDD. For example, 20200218 would be interpreted as "February 18th, 2020". You can always assume that the user will supply an 8 digit integer. Next, the program should "diagnose" the date as one of the following:

Whether the year provided is a Leap Year or not. During a Leap Year February has 29 days, and in non-Leap Years February only has 28 days. You can compute whether a year is a leap year by using the following algorithm:A Leap Year is any year that can be exactly divided by 4 (such as 2016, 2020, 2024, etc)... EXCEPT if it can be exactly divided by 100, then it isn't (such as 2100, 2200, etc)

... EXCEPT if it can be exactly divided by 400, then it is (such as 2000, 2400)

Note that the year will ALWAYS be valid. For example, 0000 is valid year, as is 9999

Next, determine if the month / day combination is valid. For example, September 30th is valid, but September 37th is not. The following chart may help you to identify whether these combinations are valid or not:

Months with 30 days: April, June, September, November

Months with 31 days: January, March, May, July, August, October, December

Months with 28 days (29 during a leap year): Feburary

If the combination is invalid you should report this to the user.

If the combination is valid you should report it to the user using the full name of the month. For example, if the date entered was 20210213 you would classify the month as "February"

You should also report the date using the correct English label for the day. For example, "February 1st" - note the "st" after the number 1. In English the following are valid labels for the numbers 1-31:

1, 21 and 31: st

2 and 22: nd

3 and 23: rd

All other numbers: th

If the date is valid you should also report the "season" of the date in question. To do this you will need to ask the user for their location (either the northern hemisphere or the southern hemisphere). You can then use the following chart to report the season as "Spring", "Summer", "Autumn" or "Winter". Note that if the user doesn't supply you with a valid entry (i.e. when prompted for a hemisphere they enter the word "apple") you should tell them their entry is invalid and that you cannot compute the season. Make it so that this input is case insensitive (i.e. "S" and "s" are both valid entries for the southern hemisphere)

Meteorological temperate seasons Northern hemisphere Southern hemisphere Start date End date Winter Summer 1 December 28 February (29th if leap year) Spring Autumn 1 March 31 May Summer Winter 1 June 31 August Autumn Spring 1 September 30 November

You may not use any advanced techniques that we have not covered to extract the date in this problem (i.e. if you've read ahead and you have learned about string or list indexing / slicing you may not use these to solve this problem). Hint: look back to last week when you extracted the ones, tens and hundreds places from a 3 digit number. A similar technique can be used here.

Here are a few sample runnings of the program (texts highlighted in yellow indicates user input):

Enter a date (YYYYMMDD): 20221320 2022 is NOT a leap year This is not a valid date in 2022
Enter a date (YYYYMMDD): 20220931 2022 is NOT a leap year This is not a valid date in 2022
Enter a date (YYYYMMDD): 20220930 2022 is NOT a leap year September 30th 2022 is a valid date Which hemisphere are you located in? (N)orth or (S)outh? N The season on this date is AUTUMN
Enter a date (YYYYMMDD): 20220229 2022 is NOT a leap year This is not a valid date in 2022
Enter a date (YYYYMMDD): 20200229 2020 is a leap year February 29th 2020 is a valid date Which hemisphere are you located in? (N)orth or (S)outh? S The season on this date is SUMMER
Enter a date (YYYYMMDD): 20231231 2023 is NOT a leap year December 31st 2023 is a valid date Which hemisphere are you located in? (N)orth or (S)outh? N The season on this date is WINTER
Enter a date (YYYYMMDD): 20190314 2019 is NOT a leap year March 14th 2019 is a valid date Which hemisphere are you located in? (N)orth or (S)outh? apple Invalid entry, cannot determine season

Hints:

Your program can assume that the user will type in an integer. You should convert all values given to you by the user into integers for calculation purposes.

Look back at Assignment #2 if you are having trouble isolating the year, month and day from the single integer that the user is providing.

There are many different conditions to test in this program, and many different ways to approach the problem. My advice is to identify the leap year first, and after that identify if the date is invalid or not -- once you've identified the supplied value as invalid you don't need to continue analyzing it.

You cannot assume that if your program works with the sample inputs above that it is complete. As a programmer you need to think about the wide range of possible inputs that could be provided and proactively test these to ensure that your algorithm is sound. The examples given here are not complete and do not cover all of the possible things that could happen. For example:

Months: What if the user enters a month that is 00? How about one that is greater than 12, like 13 or 98?

Days: What if the user enters a day that is 00? How about on that is greater than 12, like 13 or 87?

Does your program handle February 29th in a leap year? How about in a non-leap year?

How does your program handle season changes? Does it perform correctly when on the "cusp" of a season?

You should start thinking this way and start thinking about all the possible ways things could go wrong, including "edge cases" that could potentially be problematic.

Big hint: you may be able to make your program easier if you create new variables along the way. For example, if you "diagnose" the year as a leap year at the beginning of the program you can set a variable to "remember" this fact for later on.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!