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

求教!!!判断是否为闰年

zhanghang123 发布于 2010-12-22 00:19, 742 次点击
程序代码:
#include<iostream.h>
class runnian
{
public:
    runnian();
protected:
    int year;
};


runnian::runnian(int t=0)
{
    strcpy(year,t);
    if(0<t<9999)
    {
        if((t%4==0&&t%100!=0)||(t%400==0)
            cout<<t<<"是闰年"<<endl;
        else
            cout<<t<<"不是闰年"<<endl;
    }
    else
        reture ERROR:
}
int mian()
{
    runnian a;
    int y;
    cout<<"请输入一个年份:"<<endl;
    cin>>y;
    a.runnian();
}
自己写的程序,请大家帮忙改改,谢谢!!
4 回复
#2
zhoufeng19882010-12-22 09:16
楼主的代码有点惨不忍睹..
建议楼主好好学学基础知识。
程序代码:
#include<iostream.h>

#define ERROR -1
#define SUCCESS 0

class runnian
{
public:
    int _runnian( int t = 0);
public:
    int year;
};

int runnian::_runnian(int t)
{
    //strcpy(year,t);                                                                                    
    year = t;
    //if(0<t<9999)      
    if( t > 0 && t < 9999)
    {
        if(( t % 4 == 0 && t % 100 != 0)||( t % 400 == 0))
            cout << t << "是闰年" << endl;
        else
            cout << t << "不是闰年" << endl;
           
        return SUCCESS;
    }
    else
      return ERROR;
}
int main()
{
    runnian a;
    int y;
    cout << "请输入一个年份:" << endl;
    cin >> y;
    a._runnian( y);
}



 
#3
tangyz9222010-12-22 20:32
写的也太烂了啊!
#4
cnfarer2010-12-22 20:38
本论坛中有一个不错的表达式,找找吧!
#5
kspliusa2010-12-22 21:15
楼主代码错字满天啊!main都写错了!
1