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

The program for this problem deals with dates, leap years and counting number of

ID: 3676382 • Letter: T

Question

The program for this problem deals with dates, leap years and counting number of elapsed days. A number of functions are used as described in the comments in the code.
An example run with the program for this problem follows:

OUTPUT:

$ ./a.out

lab 3(a) solution by <STUDENT NAME>

test daysInMonth function

Month= 1, days in month = 31

Month= 2, days in month = 28

Month= 3, days in month = 31

Month= 4, days in month = 30

Month= 5, days in month = 31

Month= 6, days in month = 30

Month= 7, days in month = 31

Month= 8, days in month = 31

Month= 9, days in month = 30

Month= 10, days in month = 31

Month= 11, days in month = 30

Month= 12, days in month = 31

Enter number of test cases:4

Enter date after 1990 as day, month year

where month is an integer from 1 to 12

1 1 1990

days since start of 1990 =1

Enter date after 1990 as day, month year

where month is an integer from 1 to 12

29 2 2000

days since start of 1990 =3712

Enter date after 1990 as day, month year

where month is an integer from 1 to 12

29 2 2001

Error in days

Enter date after 1990 as day, month year

where month is an integer from 1 to 12

28 2 2001

days since start of 1990 =4077

INPUT

A partial C program to accomplish the goals of this problem follows, and there are some codes missing:

//lab 3(a) solution by <STUDENT NAME>

#include <stdio.h>

int daysInMonth(int month);

int daysSinceStart1990(int d,int m, int y);

int leap(int y);

int main(){

   int i,day,month,year,iCase,number;

   int nDaysMonth;

   printf("lab 3(a) solution by <STUDENT NAME> ");

   printf("test daysInMonth function ");

   for(i=1;i<=12;i++){

printf("Month= %3d, days in month = %3d ",

   i, daysInMonth(i));

   }

   printf("Enter number of test cases:");

   scanf("%d",&number);

   for (iCase=1;iCase<=number;iCase++){

printf("Enter date after 1990 as day, month year ");

printf("where month is an integer from 1 to 12 ");

scanf("%d%d%d",&day,&month,&year);

// Check if valid input values

if(year < 1990) {

   printf("Error in year ");

   continue;

}

if(month < 1 || month >12) {

   printf("Error in month ");

continue; }

nDaysMonth=daysInMonth(month)+leap(year);

printf("days since start of 1990 =%d ",

daysSinceStart1990(day,month,year));

}

return 0; }

int daysInMonth(int month){

   // use switch structure to determine number of days in month

   // month is an integer from 1 to 12 inclusive representing months

   // Jnauary through December respectively

   switch (month){

} }

int leap(int y){

   //returns 1 if a leap year, 0 otherwise

   //designed to work from at least 1990 to 2020 inclusive

}

int daysSinceStart1990(int d,int m, int y){

   //returns days since start of 1990

   //for example should return 1 for input of January 1, 1990

   //NOTE: function leap is used whenever leap year

   //determiation is required,

   //function daysInMonth is used in the calculation

   //of required days in months

   int i,iY,num;

   num=0;

return num; }

Explanation / Answer

#include <stdio.h>

include <stdlib.h>

#define LEAP_DAY 29

define LEAP_MONTH 2

#define WEEK_LENGTH 7

#define isleap(y) (((y)%4 == 0 && (y)%100 != 0) || (y)%400 == 0)

struct date {

                    int day;

                   int month;

                   int year;

static char daytab[2][13] = {

0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},

{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

};

static char *week[] ={

"Sunday",

"Monday",

"Tuesday",

"Wednesday",

"Thursday",

"Friday",

"Saturday"

};

#define REFERENCE_DATE_WDAY 3

struct date reference_date = { 1, 1, 1800 };

int day_of_year(struct date *);

int days_diff(struct date *d1, struct date *d2) {

struct date *most_recent, *least_recent;

int days;

int year;

}

int day_of_year(struct date *d) {

int i, leap, day;

day = d->day;

isleap(d->year);

for (i = 1; i < d->month; i++)

return day;

}

char **make_calendar(int month, int year)

{

int days = daytab[isleap(year)][month];

char **calendar = malloc(sizeof(char *)*days);

struct date d = { 1, month, year };

int i, j = day_of_week(&d);

calendar[0] = week[j];

j = (j+1)%WEEK_LENGTH;

for (i = 1; i < days; i++, j = (j+1)%WEEK_LENGTH)

return calendar;

}