Welcome to Westonci.ca, the place where your questions are answered by a community of knowledgeable contributors. Experience the ease of finding accurate answers to your questions from a knowledgeable community of professionals. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently.
Sagot :
Using the knowledge of computational language in python we can write the code as function, daysbewteen, which returns an integer representing the numbers of days between two dates.
Writting the code:
#include <iostream>
using namespace std;
int daysInMonth(int month, int year) //function to know the days in a month
{
//array to store the days of each month for a non-leap year
int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//array to store the days of each month for a leap year
int a2[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) //if the year is a leap year
return a2[month-1]; //value from a2 array is returned
else //else if the year is not a leap year
return a1[month-1]; //value from a1 array is returned
}
int daysBetween(int y1, int m1, int d1, int y2, int m2, int d2) //function definition
{
int days = 0; //days is initialized to zero
for(int i = y1; i <= y2; i++) //for each year from y1 to y2 loop repeats
{
if(i == y1) //if i equals to y1
{
days = days + daysInMonth(m1, y1) - d1; //for m1 days is calculated and subtract d1 from that
for(int j = m1+1; j <= 12; j++) //from the months starting m1+1
{
days = days + daysInMonth(j, i); //days in each month is added to days variable
}
}
else if(i == y2) //if i equals to y2
{
days = days + d2; //d2 is added to days
for(int j = 1; j < m2; j++) //we can only check upto m2-1 month
days = days + daysInMonth(j, i); //days in each month is added to days
}
else //else
for(int j = 1; j <= 12; j++) //for each month in that year
days = days + daysInMonth(j, i); //days in that month is added to days
}
return days; //days is returned
}
int main() //main function
{
int y1, m1, d1, y2, m2, d2; //variable declarations
cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2; //reads the input
cout << daysBetween(y1, m1, d1, y2, m2, d2); //calls the function and prints returned value
return 0;
}
See more about C++ at brainly.com/question/19705654
#SPJ1
We appreciate your time. Please revisit us for more reliable answers to any questions you may have. We hope you found this helpful. Feel free to come back anytime for more accurate answers and updated information. Thank you for using Westonci.ca. Come back for more in-depth answers to all your queries.