知道寫的很爛,發上來時希望各位兄臺指點不足:)
先謝啦,呵呵.
#include<iostream>
using namespace std;

struct date


{
unsigned int year,month,day;
};

unsigned int sum(unsigned int,unsigned int,unsigned int);
bool is_eyear(unsigned int);

void main()


{
date temp;
unsigned int total;
cout<<"please input date,formation:2005 12 05"<<endl;
cin>>temp.year>>temp.month>>temp.day;
total=sum(temp.year,temp.month,temp.day);
cout<<"total day="<<total<<endl;
}

unsigned int sum(unsigned int y,unsigned int m,unsigned int d)


{
unsigned int t=0;

if(m<1)
{
t=0;
return t;

}else if(m==1)
{
t=d;
return t;

}else
{

switch(m)
{
case 3:
if(is_eyear(y))
t=d+sum(y,m-1,29);
else t=d+sum(y,m-1,28);
break;
case 2:case 4:case 6:case 8:case 9:case 11:
t=d+sum(y,m-1,31);
break;
default :
t=d+sum(y,m-1,30);
break;
}
}
return t;
}//計算日期總數函數


/**//***************


bool is_eyear(unsigned int y)
{
if(y%400==0) return 1;
else if(y%4==0) return 1;
else return 0;
}//判斷閏年函數
**************/




bool is_eyear(unsigned int y)


{
if(y%100==0&&y%400==0) return 1;
if(y%100!=0&&y%4==0) return 1;
return 0;
}//判斷閏年函數


posted on 2005-12-28 23:12
豪 閱讀(961)
評論(6) 編輯 收藏 引用 所屬分類:
C++之夢
計算日期總數"
trackback:ping="http://www.shnenglu.com/qywyh/services/trackbacks/2222.aspx" />
-->