Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. Day of the Week In homework 2 you wrote functions that allowed you to compute

ID: 3734638 • Letter: 2

Question

2. Day of the Week In homework 2 you wrote functions that allowed you to compute differenoes between dates These functions (as well as a new one) can be useful in other programs as well, so we can put the definitions of the functions in a file, julianc, with the prototypes in julian.h to make a small ibrary. For excample, in addition to other macros, julian.h might contain the following prototypes: int julian date (int day, int son, iat yr) /* Given: the day, month, year Returns: the julian date int days.in year(int yr) /e Given: the year Returns: the susber of days in the yoar int days.in month (int mon, int yr): / Given: the sonth and year Returns: the number of days in the month int is leap(int yr): /Given: a year Returos: TRUE if the year is a leap year, FALSE othervise We would like to write a program using the above library which will determine the day of the week (Sunday, Monday. Tuesday, etc.) for any date in the 21" century. We are given that 1 an 2000 was a Saturday. A sample execution of this program would look like Enter a date (aon, day, year) (EOF to quit): 4 13 2015 4/13/2015 is a Monday Enter date(o, day, year) (EOF to quit): 5 6 2015 5/6/2015 is a Vedcesday Enter date(mom, day, year) (EOP to quit)D Your task is to write the driver that implements this program DO NOT WRITE ANY OF THE ABOVE FUNCTIONS!t. You may just se those functions in your program You will ouly write the driver (main0), and any ADDITIONAL functione yoù want, for this prograun. You can assume that the date the uer estered is always later thaa 1 Jan 2000. (To belp you out if you weed it, today's jalian date is 103) e a) Write the algorithm for the driver to kompute the day of the week given a date. b) write the code for main) MacBook Air

Explanation / Answer

Answer: See the code below:

------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include "julian.h"

//enum for week days
enum WEEKDAY {SUNDAY=0,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY};

//main() function
int main(void) {
   int mon, day, year;
   //reference date i.e. January 1, 2000
   int ref_mon = 1;
   int ref_day = 1;
   int ref_year = 2000;
   enum WEEKDAY ref_weekday = SATURDAY; //weekday on January 1, 2000
   int ref_julian_date = julian_date(ref_day,ref_mon,ref_year); //gets julian date of reference date
   int input_julian_date;
   int days_diff = 0;
   enum WEEKDAY target_weekday; //target day of week
   //days of week
   char* week_day = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
   setvbuf (stdout, NULL, _IONBF, 0);
   printf("Enter a date(mon, day, year)(EOF to quit):");
   while(scanf("%d %d %d",&mon,&day,&year)!=EOF)
   {
       printf("Enter a date(mon, day, year)(EOF to quit):");
       input_julian_date = julian_date(day,mon,year); //gets julian date for input date
       //difference between two dates;
       days_diff = input_julian_date - ref_julian_date;
       target_weekday=(ref_weekday+days_diff%7)%7-1;
       printf("%d/%d/%d is %s. ",mon,day,year,week_day[target_weekday]);
   }
   return EXIT_SUCCESS;
}

-------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote