大家好,我是论坛新人,也是c++新人~带着问题来的,希望大家帮忙看一下啊谢谢~
#include <iostream>using namespace std;
int l(int y)
{ if (y%400==0)
return 1;
else
if (y%4==0)
return 1;
else
return 0;
}
class Date
{
public:
Date(int yy,int mm,int dd){y=yy;m=mm;d=dd;}
Date(Date &p){y=p.y;m=p.m;d=p.d;}
int gety(){return y;}
int getm(){return m;}
int getd(){return d;}
private:
int y,m,d;
};
class Month
{
public:
Month(int mm,int ll);
Month(Month &p){mon=p.mon;l=p.l;}
int getm(){return mon;}
private:
int mon,l;
};
Month::Month(int mm,int ll)
{ l=ll;
switch(mm)
{ case'1':
case'3':
case'5':
case'7':
case'8':
case'10':
case'12':
mon=31;
break;
case'4':
case'6':
case'9':
case'11':
mon=30;
break;
case'2':
mon=28+l;
break;
}
}
class Year
{
public:
Year(Date dd);
Year(Year &p);
int gety(){return nday;}
private:
int nday;
Date d;
};
Year::Year(Date dd):d(dd)
{ Month m(d.getm(),l(d.gety()));
int i;
for(i=1,nday=0;i<d.getm();i++)
{ m(i,l(d.gety()));
nday+=m.getm();
}
nday+=d.getd();
}
Year::Year(Year &p):d(p.d){nday=p.nday;}
int work(Date d1(0,0,0),Date d2(0,0,0))
{ Year y1(d1),y2(d2);
int i,n=0;
for (i=d1.gety();i<d2.gety();i++)
n+=365+l(i);
n=n+y1.gety()-y2.gety();
return n;
}
void main()
{ Date date1,date2;
int yy,mm,dd;
cout<<"Please enter the beginning date:(yyyymmdd)"<<endl;
cin>>yy>>mm>>dd;
date1(yy,mm,dd);
cout<<"Please enter the endding date:(yyyymmdd)"<<endl;
cin>>yy>>mm>>dd;
date2(yy,mm,dd);
cout<<"There is "<<work(date1,date2)<<" days between "<<date1<<" and "<<date2<<endl;
}
--------------------Configuration: Year - Win32 Debug--------------------
Compiling...
Year.cpp
F:\study\VC++\Year\Year.cpp(72) : error C2064: term does not evaluate to a function
F:\study\VC++\Year\Year.cpp(79) : error C2059: syntax error : 'constant'
F:\study\VC++\Year\Year.cpp(79) : error C2059: syntax error : 'constant'
F:\study\VC++\Year\Year.cpp(80) : error C2664: '__thiscall Year::Year(class Date)' : cannot convert parameter 1 from 'class Date (__cdecl *)(void)' to 'class Date'
No constructor could take the source type, or constructor overload resolution was ambiguous
F:\study\VC++\Year\Year.cpp(80) : error C2664: '__thiscall Year::Year(class Date)' : cannot convert parameter 1 from 'class Date (__cdecl *)(void)' to 'class Date'
No constructor could take the source type, or constructor overload resolution was ambiguous
F:\study\VC++\Year\Year.cpp(82) : error C2228: left of '.gety' must have class/struct/union type
F:\study\VC++\Year\Year.cpp(82) : error C2228: left of '.gety' must have class/struct/union type
F:\study\VC++\Year\Year.cpp(89) : error C2512: 'Date' : no appropriate default constructor available
F:\study\VC++\Year\Year.cpp(89) : error C2512: 'Date' : no appropriate default constructor available
F:\study\VC++\Year\Year.cpp(93) : error C2064: term does not evaluate to a function
F:\study\VC++\Year\Year.cpp(96) : error C2064: term does not evaluate to a function
F:\study\VC++\Year\Year.cpp(97) : error C2664: 'work' : cannot convert parameter 1 from 'class Date' to 'class Date (__cdecl *)(void)'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
执行 cl.exe 时出错.
Year.obj - 1 error(s), 0 warning(s)
新人,以前学过一点别的基础语言和c语言,对类和对象很不熟悉,所以可能有各种低端错误,已经自己改了很长时间了但是实在是改不出来。。。求赐教啊TUT!谢谢了~~~~~!!
如果能不怕麻烦帮我把错误的提示解释一下就更好了=w=~