NextDate程序给出日期的下一天


c++面向对象实现计算给出的一个日期的下一天
资源截图
代码片段和文件信息
// Date.cpp: implementation of the Date class.
//
//////////////////////////////////////////////////////////////////////

#include “Date.h“


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Date::Date()
{
m_year = 1812;
m_month = 1;
m_day = 1;
Dstate = 0;

}

Date::~Date()
{

}



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

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

int Date::getYear()
{
return m_year;
}

bool Date::setYear(int y)
{
m_year = y;
return true;
}

bool Date::setDay(int d)
{
m_day = d;
return true;
}

bool Date::setMonth(int m)
{
m_month = m;
return true;
}



bool Date::IsLeap()
{
if ((m_year%4==0&&m_year%100!=0)||m_year%400 == 0)
{
return true;
}
return false;

}

Date::Date(int y int m int d)
{
m_year = y;
m_month = m;
m_day = d;
Dstate = 0;
}

Date Date::strToDate(string Datestr)
{

if (string::npos != Datestr.find_first_not_of(charTable))
{
      cout<<“出现非法字符“<        Dstate = (Dstate|CHARE);
}


int firstDivid=0;
int secondDivid=0;
firstDivid = Datestr.find_first_of(‘-‘0);
secondDivid = Datestr.find_first_of(‘-‘firstDivid+1);

if (firstDivid!=4 || !(secondDivid == 7||secondDivid==6) || 
Datestr.find_first_of(‘-‘secondDivid+1)!=string::npos )
{
cout<<“格式不对“< cout<<“正确的格式是1988-07-06“< Dstate = (Dstate|FORMATE);
}

m_year = atoi(Datestr.substr(0firstDivid).c_str());
m_month = atoi(Datestr.substr(firstDivid+1secondDivid-firstDivid).c_str());
m_day = atoi(Datestr.substr(secondDivid+1Datestr.length()-secondDivid).c_str());
if (m_year {
Dstate = (Dstate|YEARL);
cout<<“输入年份不对,小于“<
}
else if (m_year>MAXYEAR)
{
Dstate = (Dstate|YEARS);
cout<<“输入年份不对,大于“< }

if (m_month<1)
{
Dstate = (Dstate|MONTHL);
cout<<“输入月份不对,小于1“< }
else if (m_month>12)
{
Dstate = (Dstate|MONTHS);
cout<<“输入月份不对,大于12“< }

if (m_day<1)
{
Dstate = (Dstate|DAYL);
cout<<“输入日期不对,小于1“< }
else if (m_month>0 && m_month<13 && m_day > monthDayNum[m_month-1] &&m_month != 2)
{
Dstate = (Dstate|DAYS);
cout<<“输入日期不对,大于当月最大天数“< }
else if ( m_month == 2 )
{
if (((m_year%4==0 && m_year%100!=0)||m_year%400 == 0) && m_day>29)
{
Dstate = (Dstate|DAYS);
cout<<“输入日期不对,大于当月最大天数“< }
else if (m_day > 28)
{
Dstate = (Dstate|DAYS);
cout<<“输入日期不对,大于当月最大天数“< }

}


// 
//  Date newDate(m_yearm_monthm_day);
// 
// 
//   
//  return newDate;
return *this;





}

void Date::dateToStr()
{
cout< < <}

bool Date::setCharTable()
{
    
return false;
}

Date::Date(Date &d)
{
m_day = d.m_day;
m_month = d.m_month;
m_

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3198  2009-03-15 23:46  NextDateCDate.cpp

     文件       2047  2009-03-15 23:45  NextDateCDate.h

     文件     168713  2009-03-17 23:27  NextDateCDebugDate.obj

     文件          0  2009-03-17 23:27  NextDateCDebugDate.sbr

     文件     113865  2009-03-15 23:45  NextDateCDebugMain.obj

     文件          0  2009-03-15 23:45  NextDateCDebugMain.sbr

     文件     443392  2009-03-17 23:27  NextDateCDebugNextDateC.bsc

     文件     532566  2009-03-17 23:27  NextDateCDebugNextDateC.exe

     文件     805332  2009-03-17 23:27  NextDateCDebugNextDateC.ilk

     文件    2136644  2009-03-15 23:45  NextDateCDebugNextDateC.pch

     文件    1328128  2009-03-17 23:27  NextDateCDebugNextDateC.pdb

     文件      91136  2009-03-17 23:38  NextDateCDebugvc60.idb

     文件     110592  2009-03-17 23:27  NextDateCDebugvc60.pdb

     文件       1932  2009-03-15 23:45  NextDateCMain.cpp

     文件       4433  2009-03-12 23:49  NextDateCNextDateC.dsp

     文件        543  2009-03-10 23:00  NextDateCNextDateC.dsw

     文件      50176  2009-03-17 23:41  NextDateCNextDateC.ncb

     文件      49664  2009-03-17 23:41  NextDateCNextDateC.opt

     文件       1487  2009-03-17 23:27  NextDateCNextDateC.plg

     文件       3794  2009-03-13 19:39  NextDateCReleaseDate.obj

     文件      59760  2009-03-13 19:39  NextDateCReleaseMain.obj

     文件      94208  2009-03-13 19:39  NextDateCReleaseNextDateC.exe

     文件    2070968  2009-03-13 19:39  NextDateCReleaseNextDateC.pch

     文件      33792  2009-03-13 19:44  NextDateCReleasevc60.idb

     目录          0  2009-03-17 23:27  NextDateCDebug

     目录          0  2009-03-13 19:39  NextDateCRelease

     目录          0  2009-03-17 23:41  NextDateC

----------- ---------  ---------- -----  ----

              8106370                    27



............此处省略0个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)