fatal error C1004: unexpected end of file found找不出来BUG

programnewlearner 2016-05-14 03:58:54
头文件
#ifndef _DATE_H_
#define _DATE_H_
#include<iostream>
using namespace std;
class Date
{
public:
Date(int a,int b,int c);
Date(){};
Date operator +(int days);
friend ostream &operator<<(ostream &cout,Date a);
bool leapyear(int year);
void Showtime();
private:
int year,month,day;
static int days1[13];
};
#endif

类定义文件
#include "Date.h"

void Date::Showtime()
{
cout<<"日期为:"<<year<<" "<<month<<" "<<day<<endl;
}
int Date::days1[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}

Date::Date(int a,int b,int c)
{
if(b>12||b<=0||c>31||c<=0||year<=0)
{
cout<<"对象创建错误:"<<endl;
return 0;
}
else
{
month=b;
day=c;
year=a;
}
}

bool Date::leapyear(int year)
{
if(year%4==0&&year%100!=0)||year||400==0)
{
return true;
}
else
{
return false;
}
}


Date Date::operator +(int days)
{
Date a,b,c;
int Days1,Days2,Days3;
Days1=Days2=Days3=days
a=b=c=*this;
int daysAyear=365;
if(leapyear(a.year))
{
daysAyear=366;
}
else
{
daysAyear=365;
}
while(Days1>=daysAyear)
{
Days1=Days1-daysAyear;
a.year++;
this->year++;
if(leapyear(a.year))
{
daysAyear=366;
}
else
{
daysAyear=365;
}
}

if(leapyear(b.year))
{
days1[2]=29;
}
else
{
days1[2]=28;
}
while(Days2>=days1[b.month])
{
Days2=Days2-days1[b.month];
b.month++;
this->month++;
if(b.month>=13)
{
b.year++;
if(leapyear(b.year))
{
days1[2]=29;
}
else
{
days1[2]=28;
}
b.month=b.month%12;
}
}
this->month=b.month;

if(leapyear(c.year))
{
days1[2]=29;
}
else
{
days1[2]=28;
}
if((Days3+c.day)<=days1[c.month])
{
this->day=Days3+this->day;
}
else
{
while((Days3+c.day)>days1[c.month])
{
c.day=Days3+c.day-days1[c.month];
c.month++;
if(c.month>12)
{
c.year++;
c.month=c.month%12;
}
if(leapyear(c.year))
{
days1[2]=29;
}
else
{
days1[2]=28;
}
}
this->day=c.day;
}
return *this;
}

ostream &operator<<(ostream &cout,Date a)
{
cout<<"日期为:"<<a.Showtime()<<endl;
return cout;
}
测试文件
#include "Date.h"

int main()
{
Date date1(2012,3,1);
date1+50;
cout<<date1<<endl;
return 0;
}
...全文
101 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wang0635 2016-05-14
  • 打赏
  • 举报
回复
int Date::days1[13]={0,31,28,31,30,31,30,31,31,30,31,30,31} 后边应有分号
programnewlearner 2016-05-14
  • 打赏
  • 举报
回复
在构造函数有之前是这样 error C2143: syntax error : missing ';' before 'tag::id' fatal error C1004: unexpected end of file found
programnewlearner 2016-05-14
  • 打赏
  • 举报
回复
我把构造函数用参数表替代后就成了这样,我估计不是构造函数出了问题 error C2146: syntax error : missing ';' before identifier 'bool' fatal error C1004: unexpected end of file found

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧