Question: using int dayInYear and int firstDayOfYear Write a program in a source file named Weekday.cpp (starter code provided) that prompts the user to enter the

using int dayInYear and int firstDayOfYear

Write a program in a source file named Weekday.cpp (starter code provided) that prompts the user to enter the weekday the year started on and the current day of the year (i.e., 200 for the 200th day of this year). The program should output the name of the current weekday in English and German, how many days until the weekend (Saturday), and how many days until the start of the next workweek (Monday).

To create this problem do the following.

  1. Create an enum type named Weekday (with a capital W) that has the values listed in the table below.
  2. Write a function named yearDayToWeek that takes two parameters: (1) a Weekday enum value representing the first weekday of the year and (2) the number of days it has been since January 1st. The function should return a Weekday enum value that is the current weekday, based on the parameter values.
    Hint: remember that the modulus operator finds the remainder of the division. If you divide the number of days into 7-day weeks, the remaining days would be how many days you are into the last week. Suppose the year started on a Tuesday (numeric value of 2) and it is the third day of the year. Then if we count the 3 days (Tuesday, Wednesday, and Thursday), the function should return THURSDAY (numeric value of 4 = 2 + 3 - 1). Similarly, if it is the fourth day of the year, then the function should return FRIDAY (numeric value of 5 = 2 + 4 - 1). We subtract 1 because you don't otherwise we count the start day twice. With this relationship, you can calculate the current weekday using the formula (startDay + numberOfDays - 1) % 7. We use the remainder after dividing by 7 because there are 7 days in a week.
  3. Write a function named daysUntil, which takes as parameters two Weekday enum values. The function should return the number of days from the first Weekday until the second Weekday. This should never be a negative number.
  4. Write two functions named weekdayInEnglish and weekdayInGerman. Both functions should accept a Weekday enum value and return the name of the weekday in the respective language as a string. See the table below. Use a switch statement in both of these functions to return the appropriate string value.
Enum Value Day of Week Integer Value English Name German Name
SUNDAY 1 0 Sunday Sonntag
MONDAY 2 1 Monday Montag
TUESDAY 3 2 Tuesday Dienstag
WEDNESDAY 4 3 Wednesday Mittwoch
THURSDAY 5 4 Thursday Donnerstag
FRIDAY 6 5 Friday Freitag
SATURDAY 7 6 Saturday Samstag
INVALID_DAY 7 Invalid day Ungultiger Tag
Sample Output (user input is in yellow)
What weekday did January 1st land on? Enter a number between 1 (Sunday) and 7 (Saturday): 1 This year started on a Sunday. Enter the current day of the year (e.g., 180): 59 Today is Tuesday in English and Dienstag in German. This is day 3 of the week. The weekend is in 4 days. The next workweek is in 6 days.
Sample Output (user input is in yellow)
What weekday did January 1st land on? Enter a number between 1 (Sunday) and 7 (Saturday): 3 This year started on a Tuesday. Enter the current day of the year (e.g., 180): 200 Today is Friday in English and Freitag in German. This is day 6 of the week. The weekend is in 1 days. The next workweek is in 3 days.

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!