编一个Days类,给定2020(闰年)年的一个日期(月、日),计算从2020年1月1日开始到这个日期所经历的天数。
#include<iostream>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<conio.h>
#include<cmath>
#include <algorithm>
#include<windows.h>
using namespace std;
class Days
{
private:
int month;
int day;
public:
Days()
{
cout<<"input the month:";
cin>>month;
cout<<"input the day:";
cin>>day;
}
void days()
{
int sum=0;
int monday[13]={0,31,29,31,30,31,30,31,31,30,31,30,30};
for(int i=1;i<month;++i)
{
sum=sum+monday[i];
}
sum=sum+day;
cout<<"the total days is:"<<sum<<endl;
}
};
int main()
{
Days d;
d.days();
system("pause");
return 0;
}