Problem: Given an integer representing the number of days since December 31, 1972, determine the year and month on which
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Problem: Given an integer representing the number of days since December 31, 1972, determine the year and month on which
book page 300
+++++++++++++++++++++++++++++++++++
Problem: Given an integer representing the number of days since December 31, 1972, determine the year and month on which the date occurred. Useful formulas related to calendars can be found on page 300 of your C programming text. Notes: The proper use of user-defined functions is a requirement of this assignment. The user will always enter a positive (greater than zero) integer value as input. Patterns are everywhere in a calendar. Make calculations! Example Execution #1: Enter the number of days after 12/31/1972 -> 1 Month: January Year: 1973 Example Execution #2: Enter the number of days after 12/31/1972 -> 32 Month: February Year: 1973 Example Execution #3 (1973 was not a leap year): Enter the number of days after 12/31/1972 -> 60 Month: March Year: 1973 Example Execution #4: Enter the number of days after 12/31/1972 -> 91 Month: April Year: 1973 Example Execution #5: Enter the number of days after 12/31/1972 -> 121 Month: May Year: 1973 Example Execution #6: Enter the number of days after 12/31/1972 -> 152 Month: June Year: 1973 Example Execution #7: Enter the number of days after 12/31/1972 -> 18089 Month: July Year: 2022
Your guess is low. Try again: 20 Your guess is high. Try again: 10 Your guess is low. Try again: 18 Your guess is high. Try again: 12 Sorry. The number was 15. You should have gotten it by now. Better luck next time. Your design for this program should include a separate function to get the user's guess, a function to print the unsuccessful message, one to print the successful message, and one to print the sorry message. 60. Write a program that, given a person's birth date (or any other date in the Gregorian calendar), will display the day of the week the person was born. To determine the day of the week, you will first need to calculate the day of the week for December 31 of the previous year. To calculate the day for December 31, use the following formula. year year- 100 (year-1)× 365+ -]-[ year. 400 :] % 7 The formula determines the day based on the values as shown below. Day 0: Sunday Day 1: Monday Day 2: Tuesday Day 3: Wednesday Day 4: Thursday Day 5: Friday Day 6: Saturday Once you know the day for December 31, you simply calculate the days in the year before the month in question. Use a switch statement to make this calculation. (Hint: Use case 12 first, and then fall into case 11, 10...2.) If the desired month is 12, add the number of days for November (30). If it is 11, add the number of days for October (31). If it is 3, add the number of days for February (28). If it is 2, add the number of days for January (31). If you do not use a break between the months, the switch will add the days in each month before the current month. To this figure, add the day in the current month and then add the result to the day code for December 31. This number modulo seven is the day of the week. There is one more refinement. If the current year is a leap year, and if the desired date is after February, you need to add 1 to the day code. The following formula can be used to determine if the year is a leap year. (!(year % 4) && (year % 100)) || (year % 400)