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

Dates C project For this project, you will be writing functions that deal with d

ID: 3568838 • Letter: D

Question

Dates C project

For this project, you will be writing functions that deal with dates. We will use a struct with integer fields month, day and year to represent a date.

#include "date.h"
#include <stdio.h>

/* FILL IN THE MISSING CODE BELOW */

int compare_dates(date d1, date d2)
{
  
}
  

int is_leap_year(int the_year)
{

}

int day_of_year(date d)
{
}

int get_age(date birthdate, date today)
{

}

int is_birthday(date birthdate, date today)
{

}


/* DO NOT MODIFY THE CODE BELOW */
void input_date(date *dp)
{
scanf("%d/%d/%d",&(dp->month),&(dp->day),&(dp->year));
}

void print_date(date d)
{
printf("%d/%d/%d",d.month,d.day,d.year);
}

void check_age_and_birthday(date birthdate, date today)
{
printf("You are %d years old and this is ", get_age(birthdate,today));
if (!is_birthday(birthdate,today)) {
printf("not ");
}
printf("your birthday ");
}

void print_submit_status(date start, date end, date submit)
{
if (compare_dates(submit,start) == -1) {
print_date(submit);
printf(" ");
print_date(start);
printf("Submission not accepted - too early ");
}
else if (compare_dates(submit,end) == 1) {
printf("Submission not accepted - too late ");
}
else {
printf("Submission accepted ");
}
}

int days_in_month(int month, int leap_year)
{
int retval= 0;
switch(month) {
case 1: case 3:case 5:case 7:case 8:case 10:case 12:
retval = 31;
case 4:case 6:case 9:case 11:
retval = 30;
case 2:
if (leap_year)
retval = 29;
else
retval = 28;
}
return retval;
}

Explanation / Answer

#include <stdio.h>

/* FILL IN THE MISSING CODE BELOW */
struct date{
   int month;
   int year;
   int day;
};

int compare_dates(date d1, date d2)
{
if (d1.year < d2.year)
return -1;
if (d1.year > d2.year)
return 1;
if (d1.month < d2.month)
return -1;
if (d1.month > d2.month)
return 1;
if (d1.day < d2.day)
return -1;
if (d1.day > d2.day)
return 1;
return 0;

}


int is_leap_year(int the_year)
{
if ( the_year%400 == 0)
return 1;
else if ( the_year%100 == 0)
return 0;
else if ( the_year%4 == 0 )
return 1;
else
return 0;
}

int day_of_year(date d)
{
return d.day;
}

int get_age(date birthdate, date today)
{
int aget,ageb;
aget=(today.year*100+today.month)*100+today.day;
ageb=(birthdate.year*100+birthdate.month)*100+birthdate.day;
return (aget-ageb)/10000;
}

int is_birthday(date birthdate, date today)
{

if ((today.day==birthdate.day) && (today.month==birthdate.month))
return 1;
else
return 0;
}


/* DO NOT MODIFY THE CODE BELOW */
void input_date(date *dp)
{
scanf("%d/%d/%d",&(dp->month),&(dp->day),&(dp->year));
}

void print_date(date d)
{
printf("%d/%d/%d",d.month,d.day,d.year);
}

void check_age_and_birthday(date birthdate, date today)
{
printf("You are %d years old and this is ", get_age(birthdate,today));
if (!is_birthday(birthdate,today)) {
printf("not ");
}
printf("your birthday ");
}

void print_submit_status(date start, date end, date submit)
{
if (compare_dates(submit,start) == -1) {
print_date(submit);
printf(" ");
print_date(start);
printf("Submission not accepted - too early ");
}
else if (compare_dates(submit,end) == 1) {
printf("Submission not accepted - too late ");
}
else {
printf("Submission accepted ");
}
}

int days_in_month(int month, int leap_year)
{
int retval= 0;
switch(month) {
case 1: case 3:case 5:case 7:case 8:case 10:case 12:
retval = 31;
case 4:case 6:case 9:case 11:
retval = 30;
case 2:
if (leap_year)
retval = 29;
else
retval = 28;
}
return retval;
}

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