Welcome to Westonci.ca, your one-stop destination for finding answers to all your questions. Join our expert community now! Discover comprehensive solutions to your questions from a wide network of experts on our user-friendly platform. 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

Thanks for stopping by. We are committed to providing the best answers for all your questions. See you again soon. Thank you for your visit. We're dedicated to helping you find the information you need, whenever you need it. Stay curious and keep coming back to Westonci.ca for answers to all your burning questions.