正在加载图片...
-7- Problem 5-Records (10 points) Although none of the many predicted disasters came to pass,there was considerable concern in 1999 about what would happen on January 1,2000,when the calendar year rolled over to the next century.The problem-which was commonly known as the millennium bug or the Y2K problem-comes from the fact that programmers (along with everyone else)have often used two digits to represent the year.Thus,the two-digit value 99 is intended to represent the year 1999. But what about the two-digit value 00?If programs assumed that it meant 1900,all sorts of trouble might arise. Suppose that you had been hired to rewrite various C programs to be less susceptible to Y2K errors.In these programs,dates are represented using the following structure: typedef struct int month,day,year; 】dateT; Your job is to write a function int DateCompare(dateT d1,dateT d2); which takes two dates,d1 and d2,and returns (in much the same manner as the function stringcompare),one of the following values: -1 if d1 comes before d2 0 if di and d2 represent the same date +1 if di comes after d2 To address the Y2K problem,two-digit year values between 0 and 49 should be interpreted as being in the 21st century,so that the year 01 corresponds to 2001.Year values between 50 and 99 should be interpreted as being in the 20th century,so that the year 97 represents 1997.Your function should interpret any value outside the range 0 to 99 as a complete year,so that if the year field contains the value 1942,that value is taken as the year 1942. As an example,suppose that the two records d1 and d2 have the following components, corresponding to the dates March 15,99 and January 1,00: dl d2 month day year month day year 15 99 00 Calling Datecompare(d1,d2)on these values should return-1,because the year value 00 in d2 is assumed to represent the year 2000.If d1 and d2 were instead dl d2 month day year month day year 5 00 5 1 2000 calling Datecompare (d1,d2)should return 0,because these values refer to the same date(May 1,2000)– 7 – Problem 5—Records (10 points) Although none of the many predicted disasters came to pass, there was considerable concern in 1999 about what would happen on January 1, 2000, when the calendar year rolled over to the next century. The problem—which was commonly known as the millennium bug or the Y2K problem—comes from the fact that programmers (along with everyone else) have often used two digits to represent the year. Thus, the two-digit value 99 is intended to represent the year 1999. But what about the two-digit value 00? If programs assumed that it meant 1900, all sorts of trouble might arise. Suppose that you had been hired to rewrite various C programs to be less susceptible to Y2K errors. In these programs, dates are represented using the following structure: typedef struct { int month, day, year; } dateT; Your job is to write a function int DateCompare(dateT d1, dateT d2); which takes two dates, d1 and d2, and returns (in much the same manner as the function StringCompare), one of the following values: –1 if d1 comes before d2 0 if d1 and d2 represent the same date +1 if d1 comes after d2 To address the Y2K problem, two-digit year values between 0 and 49 should be interpreted as being in the 21st century, so that the year 01 corresponds to 2001. Year values between 50 and 99 should be interpreted as being in the 20th century, so that the year 97 represents 1997. Your function should interpret any value outside the range 0 to 99 as a complete year, so that if the year field contains the value 1942, that value is taken as the year 1942. As an example, suppose that the two records d1 and d2 have the following components, corresponding to the dates March 15, 99 and January 1, 00: 3 month 15 day 99 year d1 1 month 1 day 00 year d2 Calling DateCompare(d1, d2) on these values should return –1, because the year value 00 in d2 is assumed to represent the year 2000. If d1 and d2 were instead 5 month 1 day 00 year d1 5 month 1 day 2000 year d2 calling DateCompare(d1, d2) should return 0, because these values refer to the same date (May 1, 2000)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有