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.
- Create an enum type named
Weekday(with a capital W) that has the values listed in the table below. - Write a function named
yearDayToWeekthat takes two parameters: (1) aWeekdayenum value representing the first weekday of the year and (2) the number of days it has been since January 1st. The function should return aWeekdayenum 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 returnTHURSDAY(numeric value of 4 = 2 + 3 - 1). Similarly, if it is the fourth day of the year, then the function should returnFRIDAY(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. - Write a function named
daysUntil, which takes as parameters twoWeekdayenum values. The function should return the number of days from the firstWeekdayuntil the secondWeekday. This should never be a negative number. - Write two functions named
weekdayInEnglishandweekdayInGerman. Both functions should accept aWeekdayenum value and return the name of the weekday in the respective language as a string. See the table below. Use aswitchstatement 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 |
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.
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
Get step-by-step solutions from verified subject matter experts
