Start with the datescpp file on the website Fill in the miss

Start with the dates.cpp file on the website. Fill in the missing functions to enable the program to compile and correctly find the number of days between two dates. You may not change main(), we will check to ensure it is exactly the same. You may assume that the start date entered is not after the end date.

this is dates.cpp

Solution

instead of :

int duration =end -start;

use duration = getDifference( end, start)

Code:

struct Date
{
    int d, m, y;
};

const int monthDays[12] = {31, 28, 31, 30, 31, 30,
                           31, 31, 30, 31, 30, 31};

int LeapYearscount(Date da)
{
    int y = da.y;

    if (da.m <= 2)
        y--;
    return y / 4 - y / 100 + y / 400;
}

// This function returns number of days between two given
// dates
int getDifference(Date dt1, Date dt2)
{
     int n1 = dt1.y*365 + dt1.d;

    for (int i=0; i<dt1.m - 1; i++)
        n1 += monthDays[i];
n1 += LeapYearscount(dt1);


     int n2 = dt2.y*365 + dt2.d;
    for (int i=0; i<dt2.m - 1; i++)
        n2 += monthDays[i];
    n2 += LeapYearscount(dt2);

    return (n2 - n1);
}

Start with the dates.cpp file on the website. Fill in the missing functions to enable the program to compile and correctly find the number of days between two d

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site