当前位置:网站首页>Pta:7-64 what day of the year is this day

Pta:7-64 what day of the year is this day

2022-06-23 04:38:00 Sy_ Faker

Define a date class Date, Member years with data 、 month 、 Japan , There are other member functions : Constructor is used to initialize data members , Output , Leap year judgment . Write the main function : Create date object , Calculate and output the day which is the day of the year . Input format : The test input contains several test cases , One line per test case . When read in 0 0 0 When the input is over , Do not output the corresponding result .

sample input :

2006 3 5
2000 3 5
0 0 0
sample output :( In parentheses is the description )

64 (2006 year 3 month 5 Day is the... Of the year 64 God )
65 (2000 year 3 month 5 Day is the... Of the year 65 God )

#include<iostream>
using namespace std;
int A[12]={
    31,29,31,30,31,30,31,31,30,31,30,31};
int B[12]={
    31,28,31,30,31,30,31,31,30,31,30,31};
class Date
{
    
	int year;
	int month;
	int day;
	public:
		Date(int y,int m,int d):year(y),month(m),day(d){
    ;}
		void show()
		{
    
			if((year%4==0&&year%100!=0)||year%400==0)
			{
    
				for(int i=0;i<month-1;i++)
				{
    
					day+=A[i];
				}
			}
			else
			{
    
				for(int i=0;i<month-1;i++)
				{
    
					day+=B[i];
				}
			}
			cout<<day<<endl;
		}
};
int main()
{
    
	int a,b,c;
	cin>>a>>b>>c;
	while(a!=0&&b!=0&&c!=0)
	{
    
		Date d(a,b,c);
		d.show();
		cin>>a>>b>>c;
	}
}
原网站

版权声明
本文为[Sy_ Faker]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206222259538527.html