2个回答
展开全部
#include<iostream.h>
class date
{
public:
date(){}
void set(int p1,int p2,int p3)
{
year=p1;month=p2;day=p3;
}
int year,month,day;
};
int a[]={31,28,31,30,31,30,31,31,30,31,30,31},*p1,*p2,*p3,i=1,k=0;
int main()
{
int days(date k);
date m,n;
int p1,p2,p3;
cout<<"请依次输入年·月·日:"<<endl;
cin>>p1>>p2>>p3;
if(p1%4==0&&p1%100!=0||p1%400==0)
a[1]=29;
if(p2>12||p3>a[p2-1])
cout<<"您的输入有误!"<<endl;
else m.set(p1,p2,p3);
cout<<"这天是该年的第"<<days(m)<<"天。"<<endl;
cout<<"请依次输入年·月·日:"<<endl;
cin>>p1>>p2>>p3;
if(p1%4==0&&p1%100!=0||p1%400==0)
a[1]=29;
if(p2>12||p3>a[p2-1])
cout<<"您的输入有误!"<<endl;
else n.set(p1,p2,p3);
cout<<"这天是该年的第"<<days(n)<<"天。"<<endl;
cout<<"这之间相隔"<<days(n)-days(m)<<"天."<<endl;
return 0;
}
int days(date k)
{int i,c=0;
for(i=0;i<k.month-1;i++)
c+=a[i];
c+=k.day;
return c;
}
这个应该符合你的要求,参考下。
class date
{
public:
date(){}
void set(int p1,int p2,int p3)
{
year=p1;month=p2;day=p3;
}
int year,month,day;
};
int a[]={31,28,31,30,31,30,31,31,30,31,30,31},*p1,*p2,*p3,i=1,k=0;
int main()
{
int days(date k);
date m,n;
int p1,p2,p3;
cout<<"请依次输入年·月·日:"<<endl;
cin>>p1>>p2>>p3;
if(p1%4==0&&p1%100!=0||p1%400==0)
a[1]=29;
if(p2>12||p3>a[p2-1])
cout<<"您的输入有误!"<<endl;
else m.set(p1,p2,p3);
cout<<"这天是该年的第"<<days(m)<<"天。"<<endl;
cout<<"请依次输入年·月·日:"<<endl;
cin>>p1>>p2>>p3;
if(p1%4==0&&p1%100!=0||p1%400==0)
a[1]=29;
if(p2>12||p3>a[p2-1])
cout<<"您的输入有误!"<<endl;
else n.set(p1,p2,p3);
cout<<"这天是该年的第"<<days(n)<<"天。"<<endl;
cout<<"这之间相隔"<<days(n)-days(m)<<"天."<<endl;
return 0;
}
int days(date k)
{int i,c=0;
for(i=0;i<k.month-1;i++)
c+=a[i];
c+=k.day;
return c;
}
这个应该符合你的要求,参考下。
展开全部
// 闰年
int isLeap(int year)
{
if(year%400==0 ||((year%4==0)&&(year%100!=0))) return 1;
else return 0;
}
main()
{
int year,month,day;
int d=0;
int leap;
scanf("%d-%d-%d", &year, &month, &day);
leap = isLeap(year);
switch(month)
{
case 12: d+=30;
case 11: d+=31;
case 10: d+=30;
case 9: d+=31;
case 8: d+=31;
case 7: d+=30;
case 6: d+=31;
case 5: d+=30;
case 4: d+=31;
case 3: d+=28+leap;
case 2: d+=31;
case 1: d+=day;
}
printf("%d", d;);
}
int isLeap(int year)
{
if(year%400==0 ||((year%4==0)&&(year%100!=0))) return 1;
else return 0;
}
main()
{
int year,month,day;
int d=0;
int leap;
scanf("%d-%d-%d", &year, &month, &day);
leap = isLeap(year);
switch(month)
{
case 12: d+=30;
case 11: d+=31;
case 10: d+=30;
case 9: d+=31;
case 8: d+=31;
case 7: d+=30;
case 6: d+=31;
case 5: d+=30;
case 4: d+=31;
case 3: d+=28+leap;
case 2: d+=31;
case 1: d+=day;
}
printf("%d", d;);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询