展开全部
#include <iostream>
using namespace std;
struct Date
{
int year;
int month;
int day;
};
int isLeapyear(Date d)
{
if((d.year%400==0) || (d.year%100!=0) && (d.year%4==0))
return 1;
else
return 0;
}
int monthDay(Date d)
{
switch(d.month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: return 31;
case 2:
if(isLeapyear(d))
return 29;
else
return 28;
case 4:
case 6:
case 9:
case 11: return 30;
default: return 0;
}
}
int timeDay(Date d)
{
int td = 0;
Date temp = d;
for(int i = 1; i < d.month; i++)
{
temp.month = i;
td += monthDay(temp);
}
td += temp.day;
return td;
}
void main()
{
Date date;
cout << "请输入年:";
cin >> date.year;
cout << "请输入月:";
cin >> date.month;
cout << "请输入日:";
cin >> date.day;
cout << "该日在本年中是第" << timeDay(date) << "天" << endl;
}
using namespace std;
struct Date
{
int year;
int month;
int day;
};
int isLeapyear(Date d)
{
if((d.year%400==0) || (d.year%100!=0) && (d.year%4==0))
return 1;
else
return 0;
}
int monthDay(Date d)
{
switch(d.month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: return 31;
case 2:
if(isLeapyear(d))
return 29;
else
return 28;
case 4:
case 6:
case 9:
case 11: return 30;
default: return 0;
}
}
int timeDay(Date d)
{
int td = 0;
Date temp = d;
for(int i = 1; i < d.month; i++)
{
temp.month = i;
td += monthDay(temp);
}
td += temp.day;
return td;
}
void main()
{
Date date;
cout << "请输入年:";
cin >> date.year;
cout << "请输入月:";
cin >> date.month;
cout << "请输入日:";
cin >> date.day;
cout << "该日在本年中是第" << timeDay(date) << "天" << endl;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询