7-10 该日是该年的第几天
分数 10
全屏浏览题目
切换布局
作者 east
单位 福州大学
定义一个日期类Date,内有数据成员年、月、日,另有成员函数:构造函数用于初始化数据成员,输出,闰年的判断。
编写主函数:创建日期对象,计算并输出该日是该年的第几天。 输入格式: 测试输入包含若干测试用例,每个测试用例占一行。当读入0 0 0时输入结束,相应的结果不要输出。
输入样例:
2006 3 5
2000 3 5
0 0 0
输出样例:(括号内为说明)
64 (2006年3月5日是该年的第64天)
65 (2000年3月5日是该年的第65天)
#include <iostream>
using namespace std;
class Date
{
public:
Date(int ,int ,int);
void isleap();
void prin();
private:
int year, month, day,sum=0;
};
Date::Date(int a,int b,int c)
{
year = a; month = b; day = c;
}
void Date::isleap()
{
if (year % 4 == 0 && year % 100 != 0 || year % 400==0)sum++;
}
void Date::prin()
{
switch (month)
{
case 12:sum += 30;
case 11:sum += 31;
case 10:sum += 30;
case 9:sum += 31;
case 8:sum += 31;
case 7:sum += 30;
case 6:sum += 31;
case 5:sum += 30;
case 4:sum += 31;
case 3:sum += 28;
case 2:sum += 31;
case 1:sum += day;
}
cout << sum << endl;
}
int main()
{
while (1)
{
int a, b, c;
cin >> a >> b >> c;
if (a == b && b == c)break;
else
{
Date h(a, b, c);
h.isleap();
h.prin();
}
}
return 0;
}