初学C++,在结构体中写函数及一些C++语言需要的一些格式
看代码
#include<iostream>
#include<cstdio>
using namespace std;
struct what_day
{
int year;
int month;
int day;
void count(int year,int month,int day)
{
int s[12]={0,31,28,31,30,31,30,31,31,30,31,30};
int sum=day;
for(int i=0;i<month;i++)
{
sum=sum+s[i];
}
if((year%400||(year%4==0&&year%100))&&month>2)
{
sum++;
}
cout<<sum<<endl;
}
};
int main()
{
cout<<"please input year month day"<<endl;
what_day num;
cin>>num.year>>num.month>>num.day;
num.count(num.year,num.month,num.day);
return 0;
}
时间: 2024-10-13 15:46:41