CS 13A

                                    Homework #3 – Arrays

 

1. Write an integer function, daysBetweenDates(int m1, int d1,int y1, int m2, int d2,int y2),  that returns the number of days between two dates. 

 

2. Write a main procedure that calls function daysBetweenDates in a loop, and calculates the days between the dates in the rows of the following set of arrays:

 

 

startDate

02 23 2003

05 10 1999

11 21 2000

04 22 2003

 

finishDate

07 13 2006

12 06 2005

03 16 2006

09 11 2003

 

Notes:

1.  First assume that the dates are in the same year.  Convert each date to the number of days from the first day of the year to the given date, and then subtract the corresponding (converted) dates.  For example:  02 23 is converted to 31 + 23 = 54, and 07 13 is converted to 31 + 28 + 31 + 30 + 31 + 30 + 13 = 194.  194 – 54 = 144 is the number of days between Feb 23 and July 13 (within the same year and not in a leap year). 

 

2.  If the dates are not necessarily within the same year, convert each date to the number of days from the first day of the earlier year.  Then subtract.  For example:  02 23 2003 is converted to 31 + 23 = 54.  And 07 13 2006 is converted to 365 + 366 + 365 + 31 + 28 + 31 + 30 + 31 + 30 + 13 = 1290.  So, the number of days between the two dates is 1290 – 54 = 1236.