Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need a program that uses selection but avoids using arrays and structures. Problem: Given as input the year, day of the week number (0

image text in transcribed

i need a program that uses selection but avoids using arrays and structures.

image text in transcribed

Problem: Given as input the year, day of the week number (0 [Sunday] through 6 [Saturday]), and occurrence number, determine the corresponding date. On page 300 of your C programming text there are several useful formulas given as part of problem 60. All input will be integer data and your program will only be tested with years from 1800 to 2100. Example Execution #1: Enter year number -> 2021 Enter day of week number -> 1 Enter occurrence number -> 11 Desired occurrence #11 of Monday in 2021: March 15 Example Execution #2: Enter year number -> 2020 Enter day of week number -> 6 Enter occurrence number -> 9 Desired occurrence #9 of Saturday in 2020: February 29 Example Execution #3: Enter year number -> 2021 Enter day of week number -> 5 Enter occurrence number -> 1 Desired occurrence #1 of Friday in 2021: January 1 ((year 1)365+ [year -]- year - 17 [year - 1 + 100 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)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions