| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 434 人关注过本帖
标题:大家好,我是论坛新人,也是c++新人~带着问题来的,希望大家帮忙看一下啊谢 ...
取消只看楼主 加入收藏
jojo59516
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-4-2
结帖率:25%
收藏
 问题点数:0 回复次数:2 
大家好,我是论坛新人,也是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=~
搜索更多相关主题的帖子: include private public 
2012-04-02 23:10
jojo59516
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-4-2
收藏
得分:0 
回复 3楼 霁色荣光
才发现自己没有写注释,不过你居然看完了。。。太谢谢了,根据你说的我来改一下试试~因为都是自学的所以有些概念还比较模糊。。
构造函数只能用来初始化不能被调用是么?本来我是写了一个成员函数的后来去掉了T T
2012-04-03 12:43
jojo59516
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-4-2
收藏
得分:0 
回复 3楼 霁色荣光
我已经运行出正确答案了~再次谢谢你~我不仅弄对了程序也更好地理解了构造函数的作用~~好高兴~~
2012-04-03 13:13
快速回复:大家好,我是论坛新人,也是c++新人~带着问题来的,希望大家帮忙看一下 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032739 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved