三天打鱼两天晒网c++实现
- include using namespace std; class Days { public:
int setdays(); int judge(int q); int totaldays(); void
ds(); int year; int month; int day; }; int Days::setdays()
{ cout<<“请输入日期(2010.01.01之后):”<<endl; cin>>year>>month>>day;
if(year<2010||month<1||month>12||day<1||day>31) {
cout<<“输入有误”<<endl;
setdays(); } return 0; } int Days::judge(int q) { int temp; if(year%40 && year%100!=0||year%4000) temp=1; else
temp=0; return temp; } int Days::totaldays() { int sum=0,i,j;
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}; if(judge(year)1)
for(i=0;i<month-1;++i)
sum=sum+a[i];
else
for(i=0;i<month-1;++i)
sum=sum+b[i];
for(j=2010;j<year;++j)
if(judge(j)1)
sum=sum+366;
else
sum=sum+365;
sum+=day;
return sum; } void Days::ds() { int n,m; n=totaldays(); m=n%5; if(m1||m2||m==3) cout<<“这一天打渔”<<endl; else
cout<<“这一天晒网”<<endl; } int main() { Days days; days.setdays();
days.totaldays(); days.ds(); return 0; }