注册 登录
编程论坛 C++教室

这个小程序怎么改 谢谢

yanpeisen 发布于 2008-11-01 00:36, 836 次点击
#include <iostream.h>

class Tdate
{
    public:
        void set(int m,int d, int y)
        {
            month=m;  day=d;  year=y;
        }
        int Isleapyear()
       {
            return(year%4==0&&year%100!=0)||(year%400==0);
        }
        void print()
        {
            cout<<month<<"/"<<day<<"/"<<year<<endl;
        }
    private:
        int month;  int day;  int year;
}
void main()                    [bo]错误在这  [/bo]  //Tdate' followed by 'void' is illegal (did you forget a ';'?)
{
    Tdate a;
    a.set(10,1,1949);
    a.print();
    if(a.Isleapyear)
        cout<<"It is a leap year!"<<endl;
    else
        cout<<"It is not a leap year!"<<endl;
}
8 回复
#2
blueboy820062008-11-01 00:40
定义完类后要加分号!
#3
shmilytong2008-11-01 01:17
恩,楼上正确
#4
vfdff2008-11-01 01:22
就是 类定义最后嗨需要个分号";"
class CLASS{

} ;
#5
soar20082008-11-01 11:20
if(a.Isleapyear)应该为if(a.Isleapyear())
#6
shirley蝶2008-11-01 11:44
回复 2# 的帖子
版主,我想问一下下面的定义有没有问题,下面是楼主定义的类中的一个函数:
int Isleapyear()
       {
            return(year%4==0&&year%100!=0)||(year%400==0);
        }
这个函数的意思是什么那?是不是应该这样写那:
int Isleapyear(int)
{
if(year%4==0&&year%100!=0||year%400==0)
cout<<1;
else cout<<0;
}
#7
泉水天堂2008-11-01 16:08
回复 6# 的帖子

你可以这样改
 int Isleapyear(int)
{
  if(year%4==0&&year%100!=0||year%400==0)
  return 1;
  return 0;
}

这个函数需要一个返回值,你那输出的数字对函数来说没有意义
#8
mbstorm2008-11-01 20:46
同意
#9
ling1212112008-11-01 21:35
同意
1