当前位置: 代码迷 >> C语言 >> 帮忙找下错误吧 谢谢!
  详细解决方案

帮忙找下错误吧 谢谢!

热度:41   发布时间:2008-03-14 11:19:36.0
帮忙找下错误吧 谢谢!
//Date.h
class Date
{
public:
    void setDate(int,int,int);
    Date(int y,int m,int d);
    Date::Date()
{
    year=month=day=0;
}


    int getYear();
    int getMonth();
    int getDay();
private:
        int year;
        int month;
        int day;

};


//成员函数
void Date::setDate(int y,int m,int d)
{
    year=(y>=0&&y<=12)?y:0 ;
    month=(m>=0&&m<=12)?m:0 ;
    switch(m)  ///某个月的天数的具体分析
    {
    case '1':;
    case '3':;
    case '5':;
    case '7':;
    case '8':;
    case '10':;
    case '12':;  day=(d>=0&&d<=31)?d:0; break;
    case '4':;
    case '6':;
    case '9':;
    case '11':; day=(d>=0&&d<=30)?d:0 ; break;
        default: if(  ( (y%4==0)&&(y%100!=0) )||(y%400==0) )  //判断瑞年2月的天数是否合法
                     day=(d>=0&&d<=29)?d:0 ;
               else  day=(d>=0&&d<=28)?d:0 ;
                break;


    
    
}

//日期值的输出函数
int Date::getYear()
{
    return year;
}


int Date::getMonth()
{
    return month;
}


int Date::getDay()
{
    return day;
}


//测试函数
#include <iostream.h>
#include "Date.h"

void main()
{
    Date d;
    cout<<"原始时间是(年-月-日的方式输出):"<<d.getYear()<<"-"<<d.getMonth()<<"-"<<d.getDay()<<endl;

    d.setDate(1,5,31);

    cout<<"合法修正后的时间输出是:"<<d.getYear()<<"-"<<d.getMonth()<<"-"<<d.getDay()<<endl;


}
搜索更多相关的解决方案: 分析  private  public  

----------------解决方案--------------------------------------------------------
发到C++.
----------------解决方案--------------------------------------------------------
我已经帮他找了..少了个大括号
----------------解决方案--------------------------------------------------------
  相关解决方案