给定某个年月日,计算出这天属于该年的第几天.要就写出计算闰年的函数和计算日期函数.用C++
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/03 05:42:32
![给定某个年月日,计算出这天属于该年的第几天.要就写出计算闰年的函数和计算日期函数.用C++](/uploads/image/z/10096210-10-0.jpg?t=%E7%BB%99%E5%AE%9A%E6%9F%90%E4%B8%AA%E5%B9%B4%E6%9C%88%E6%97%A5%2C%E8%AE%A1%E7%AE%97%E5%87%BA%E8%BF%99%E5%A4%A9%E5%B1%9E%E4%BA%8E%E8%AF%A5%E5%B9%B4%E7%9A%84%E7%AC%AC%E5%87%A0%E5%A4%A9.%E8%A6%81%E5%B0%B1%E5%86%99%E5%87%BA%E8%AE%A1%E7%AE%97%E9%97%B0%E5%B9%B4%E7%9A%84%E5%87%BD%E6%95%B0%E5%92%8C%E8%AE%A1%E7%AE%97%E6%97%A5%E6%9C%9F%E5%87%BD%E6%95%B0.%E7%94%A8C%2B%2B)
给定某个年月日,计算出这天属于该年的第几天.要就写出计算闰年的函数和计算日期函数.用C++
给定某个年月日,计算出这天属于该年的第几天.要就写出计算闰年的函数和计算日期函数.
用C++
给定某个年月日,计算出这天属于该年的第几天.要就写出计算闰年的函数和计算日期函数.用C++
bool IsLeapYear(int nYear)
{
if (0 > nYear)
return false;
if (nYear%100 == 0)
{//400
return (nYear%400 == 0);
}
return (nYear%4 == 0);
}
int GetNormalIndex(int nMonth,int nDay)
{
int nRet = nDay;
if (nMonth > 1)
nRet += 31;
if (nMonth > 2)
nRet += 28;
if (nMonth > 3)
nRet += 31;
if (nMonth > 4)
nRet += 30;
if (nMonth > 5)
nRet += 31;
if (nMonth > 6)
nRet += 30;
if (nMonth > 7)
nRet += 31;
if (nMonth > 8)
nRet += 31;
if (nMonth > 9)
nRet += 30;
if (nMonth > 10)
nRet += 31;
if (nMonth > 11)
nRet += 30;
return nRet;
}
int GetDayIndex(int nYear,int nMonth,int nDay)
{
bool bIsLeapYear = IsLeapYear(nYear);
int nRet = GetNormalIndex(nMonth,nDay);
return bIsLeapYear?nRet+1:nRet;
}