c++求助大神,我这个代码编译通过了,但是运行的时候又说源文件未编译,其他的代码又能运行

#include<iostream>
#include<math.h>
using namespace std;
class cDate_t
{
public:

cDate_t();
cDate_t(int y,int m,int d):year(y),month(m),day(d){} //构造函数

cDate_t operator+(int days) //实现对符号+的重载
{
cDate_t d2;
d2.day=this->day+days; //天数相加
d2.month=this->month; //月份暂且不变
d2.year=this->year; //年份暂且不变
}

cDate_t operator-(int days) //实现对符号-的重载
{

cDate_t d2;
d2.day=abs(this->day-days);
d2.month=this->month;
d2.year=this->year;

}

int IsLeapYear(int y) //判断这一年是不是闰年
//判断方法:一年能被4整除不能被100整出,能被400整除
{
return(y%100!=0&&y%4==0)||(y%400==0);
}

void fd() //找到相加或相减之后的日期是什么时候
{
cDate_t d0;
if(IsLeapYear(d0.year)) //如果是闰年的话
{
int d[]={31,29,31,30,31,30,31,31,30,31,30,31}; //2月份是29天
while(d0.day>d[d0.month-1]) //如果天数大于当月的天数
{
d0.day-=d[d0.month-1]; //则天数要进行做差
d0.month++; //月份增加
if(d0.month<13)
{
continue;
}
if(d0.month==13) //如果月份增加至13的话,则从第二年开始
{
d0.month=1; //月份从第二年的1月份开始
d0.year+=1; //年份增加1
}
if(d0.day<=d[d0.month-1])
{
break;
}
}

}
else
{
int d[]={31,28,31,30,31,30,31,31,30,31,30,31}; //若不是闰年的话,2月份就是28天

while(d0.day>d[d0.month-1])
{
d0.day-=d[d0.month-1];
d0.month++;
if(d0.month<13)
{
continue;
}
if(d0.month==13)
{
d0.month=1;
d0.year+=1;
}
if(d0.day<=d[d0.month-1])
{
break;
}
}
}

cout<<"Year:"<<" "<<d0.year<<"Month:"<<" "<<d0.month<<"Day:"<<" "<<d0.day<<endl;
}

private:
int year;
int month;
int day;

};

int main()
{
cout<<"please input the date:"<<" "<<endl;
int a,b,c;
cin>>a>>b>>c;
cDate_t dm(a,b,c);
cDate_t dd;
cout<<"please input how many days you want to plus:"<<" ";
int m;
cin>>m;
dd=dm-m;
dd.fd();
return 0;
}

慕工程4384412
浏览 1219回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP