软题库 学习课程
当前位置:信管网 >> 在线考试中心 >> 试题查看
试题题型【分析简答题】
试题内容

阅读以下说明和C函数,填充函数中的空缺,将解答填入答题纸的对应栏内。
【说明】
函数GetDateld(DATE date)的功能是计算并返回指定合法日期date是其所在年份的第几天。例如,date表示2008年1月25日时,函数的返回值为25,date表示2008年3月3日时,函数返回值为63。
函数Kday_Date(int  theyear,int k)的功能是计算并返回指定合法年份theyear(theyear≥1900)的第k天(1≤k≤365)所对应的日期。例如,2008年的第60天是2008年2月29日,2009 年的第60天是2009年3月1日。
函数isLeapYear(int y)的功能是判断y代表的年份是否为闰年,是则返回1,否则返回0。
DATE 类型定义如下:
typedef   struct  {
int  year ,month ,day;
}DATE;

【C函数1】
int  GetDateld(  DATE  date  )
{
const   int  days _month[13]  =  {  0,31,28,31,30,31,30,31,31,30,
31,30 ,31 );
int i ,date_id = date.day;
for (  i =  0;  i < (1) ; i++ )
date_id  +=   days_month[i];
if (   (2)  && isLeapYear(date.year)   )  date_id++;
return date_id;
}
【C函数2】
(3)    Kday_Date(int   theyear ,int  k)
{
int i;
DATE  date;
int  days_month(13) = { 0,31,28,31,30,31,30,31,31,30,31,30,31};
assert(k>=1  &&  k<=365 && theyear>=1900);    /*不满足断言时程序终止*/
date .year =      (4)      ;
if   (isLeapYear(date.year))     days_month[2]++;
for (i=1;  ;  )    {
k = k - days_month[i++];
if  (k<=0) { date .day = k + (5) ; date.month = i-1; break; }
}
return date;
}

查看答案

相关试题