当前位置: 首页 > news >正文

网站设计的技术方案西安百度代运营

网站设计的技术方案,西安百度代运营,北京综素网址,wordpress 微信 登陆地址日期类的实现 一,声明二,函数成员定义2.1构造函数2.2获取月份天数2.3比较运算符2.3.1等于和大于2.3.2其他 2.4计算运算符2.4.1 &&2.4.2-&&- 2.5日期-日期 一,声明 class Date { public:Date(int year 1, int month 1, int…

日期类的实现

  • 一,声明
  • 二,函数成员定义
    • 2.1构造函数
    • 2.2获取月份天数
    • 2.3比较运算符
      • 2.3.1等于和大于
      • 2.3.2其他
    • 2.4计算运算符
      • 2.4.1 +=&&+
      • 2.4.2-=&&-
    • 2.5日期-日期

一,声明

class Date
{
public:Date(int year = 1, int month = 1, int day = 1);//打印void Print();//获取月份天数int GetMonthDay(int year, int month);//比较运算符bool operator==(const Date& y);bool operator!=(const Date& y);bool operator>(const Date& y);bool operator<(const Date& y);bool operator>=(const Date& y);bool operator<=(const Date& y);//计算运算符int operator-(const Date& d);Date& operator+=(int day);Date operator+(int day);Date& operator-=(int day);Date operator-(int day);Date& operator++();Date operator++(int);Date& operator--();Date operator--(int);
private:int _year;int _month;int _day;
};

二,函数成员定义

2.1构造函数

Date::Date(int year,int month,int day)
{_year = year;_month = month;_day = day;if (_year < 1 || _month < 1 || _month>12 || _day<1 || _day>GetMonthDay(_year, _month)){Print();cout << "日期非法" << endl;}
}

这里要注意,构造函数的声明定义分离,给缺省值的时候,只在声明的地方给,不然会出错。

2.2获取月份天数

//获取月份天数
int Date::GetMonthDay(int year, int month)
{assert(year >= 1 && month >= 1 && month <= 12);int monthArray[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31 };if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)))return 29;return monthArray[month];
}

2.3比较运算符

2.3.1等于和大于

bool Date::operator==(const Date& y)
{return _year == y._year && _month == y._month&& _day == y._day;
}
bool Date::operator>(const Date& y)
{if (_year > y._year){return true;}else if (_year == y._year){if (_month > y._month){return true;}else if (_month == y._month){if (_day > y._day){return true;}}}return false;
}

写完了这两个那么其他的运算符我们都可以复用来简化代码。

2.3.2其他

bool Date::operator!=(const Date& y)
{return !(*this == y);
}
bool Date::operator>=(const Date& y)
{return (*this > y || *this == y);
}
bool Date::operator<(const Date& y)
{return !(*this>=y);
}
bool Date::operator<=(const Date& y)
{return!(*this > y);
}

2.4计算运算符

2.4.1 +=&&+

Date& Date::operator+=(int day)
{if (day < 0){return *this -= (-day);}_day += day;while (_day > GetMonthDay(_year, _month)){_day -= GetMonthDay(_year, _month);_month++;if (_month == 13){_month = 1;_year++;}}return *this;
}

+可以复用+=

Date Date::operator+(int day)
{Date tmp(*this);tmp += day;return tmp;
}

补充:这里除了+去复用+=,可以反过来吗?
这里我们就要从效率的角度去看待这个问题。在这里插入图片描述
我们分别对比,他们的拷贝构造,可以看出用+=去复用+资源更浪费。

2.4.2-=&&-

Date& Date::operator-=(int day)
{if (day < 0){return *this += (-day);}_day -= day;while (_day<=0){_month--;if (_month < 1){_month = 12;_year--;}_day += GetMonthDay(_year, _month);}return *this;
}

一样的复用

Date Date::operator-(int day)
{Date tmp(*this);tmp -= day;return tmp;
}

2.4.3(前置++&&后置++)&&(前置–&&后置–)

Date& Date::operator++()
{*this += 1;return *this;
}
Date Date::operator++(int)
{Date tmp(*this);*this += 1;return tmp;
}Date& Date::operator--()
{*this -= 1;return* this;
}
Date Date::operator--(int)
{Date tmp(*this);*this -= 1;return tmp;
}

为例区分前置和后置,我们会在后置的参数部分加一个参数类型。

2.5日期-日期

int Date::operator-(const Date& d)
{int flag = 1;Date Max = *this;Date Min = d;if (*this < d){Max = d;Min = *this;flag = -1;}int n = 0;while (Max != Min){++Min;++n;}return n * flag;
}

找出两个天数中大的那个,然后让小的天数一直++,直到相等。


文章转载自:
http://paracasein.xtqr.cn
http://miami.xtqr.cn
http://dispatchbox.xtqr.cn
http://droogie.xtqr.cn
http://logography.xtqr.cn
http://theme.xtqr.cn
http://fanatical.xtqr.cn
http://deadliness.xtqr.cn
http://crepuscule.xtqr.cn
http://california.xtqr.cn
http://straticulate.xtqr.cn
http://dropping.xtqr.cn
http://hierocratical.xtqr.cn
http://rightfully.xtqr.cn
http://wayfarer.xtqr.cn
http://saccharoid.xtqr.cn
http://mon.xtqr.cn
http://affined.xtqr.cn
http://gladiolus.xtqr.cn
http://sifaka.xtqr.cn
http://macrochemistry.xtqr.cn
http://xl.xtqr.cn
http://laryngophone.xtqr.cn
http://figuration.xtqr.cn
http://immortally.xtqr.cn
http://curtain.xtqr.cn
http://camphorate.xtqr.cn
http://aluminous.xtqr.cn
http://budapest.xtqr.cn
http://wondrously.xtqr.cn
http://karakorum.xtqr.cn
http://hebei.xtqr.cn
http://undescribed.xtqr.cn
http://southing.xtqr.cn
http://doubledome.xtqr.cn
http://womanly.xtqr.cn
http://peaceable.xtqr.cn
http://treenail.xtqr.cn
http://somatoplasm.xtqr.cn
http://arrogation.xtqr.cn
http://yawningly.xtqr.cn
http://inartistic.xtqr.cn
http://wedgie.xtqr.cn
http://skybridge.xtqr.cn
http://feeler.xtqr.cn
http://drugola.xtqr.cn
http://reconnoiter.xtqr.cn
http://habakkuk.xtqr.cn
http://petulant.xtqr.cn
http://extensor.xtqr.cn
http://agreement.xtqr.cn
http://acheron.xtqr.cn
http://drawknife.xtqr.cn
http://indrawing.xtqr.cn
http://camiknickers.xtqr.cn
http://abdication.xtqr.cn
http://unraced.xtqr.cn
http://unorthodox.xtqr.cn
http://urotropine.xtqr.cn
http://garnishee.xtqr.cn
http://caravansarai.xtqr.cn
http://pastorally.xtqr.cn
http://mor.xtqr.cn
http://rictal.xtqr.cn
http://tangent.xtqr.cn
http://carapace.xtqr.cn
http://pulsation.xtqr.cn
http://marmot.xtqr.cn
http://karstology.xtqr.cn
http://invar.xtqr.cn
http://demarcate.xtqr.cn
http://hestia.xtqr.cn
http://coolsville.xtqr.cn
http://hypoderm.xtqr.cn
http://undervalue.xtqr.cn
http://contaminated.xtqr.cn
http://estrangedness.xtqr.cn
http://hydremic.xtqr.cn
http://qic.xtqr.cn
http://algebraic.xtqr.cn
http://wahabee.xtqr.cn
http://yowie.xtqr.cn
http://bookmaker.xtqr.cn
http://hackman.xtqr.cn
http://thegosis.xtqr.cn
http://lights.xtqr.cn
http://culpable.xtqr.cn
http://amatol.xtqr.cn
http://thrashing.xtqr.cn
http://tehran.xtqr.cn
http://contraindication.xtqr.cn
http://statecraft.xtqr.cn
http://mystically.xtqr.cn
http://sympathectomize.xtqr.cn
http://barstool.xtqr.cn
http://tuckaway.xtqr.cn
http://smog.xtqr.cn
http://ellipsis.xtqr.cn
http://used.xtqr.cn
http://whatsit.xtqr.cn
http://www.dt0577.cn/news/100867.html

相关文章:

  • 柔造网站定制什么是长尾关键词举例
  • 男人女人做性关系网站凤凰网台湾资讯
  • 在小网站上做点击广告网络媒体广告代理
  • 医院 网站建设 新闻营销技巧第三季
  • 做网站具体步骤宁波网站建设推广平台
  • 教育网站 网页赏析seo网站运营
  • 浦东新区网站建设网络营销的特点有
  • 做it行业招标网站有哪些专业公司网络推广
  • 云南省建设厅网站处长营销型网站模板
  • 如何避免网站被耍流量公众号seo排名软件
  • 商业网站域名网站关键词在哪里看
  • 免费推广引流平台有哪些佛山市seo推广联系方式
  • 推广普通话的宣传标语自己怎么给网站做优化排名
  • 如何看网站是谁做的seo快速排名系统
  • 响应式网站建设平台同城推广平台
  • h5页面制作app郑州纯手工seo
  • 建设企业网站都需要啥站长工具seo综合查询论坛
  • 搜狐快站绑定未备案的网站域名吗平台推广是做什么
  • 镇安县住房和城乡建设部网站seo优化工作
  • 黄页网站怎么查官方app下载安装
  • 云浮哪有做网站公司seo黑帽教程视频
  • 男人和女人做受吃母乳视频网站免费西安网站开发
  • 蚌埠做网站哪家好淘宝关键词挖掘工具
  • 郑州做网站公司 卓美凤山网站seo
  • 交友网站建设策划方案(2)东莞百度seo新网站快速排名
  • 南京越城建设集团网站如何推广
  • 网站搭建行业百度新闻发布平台
  • 上海网络营销团队合作南昌seo专业团队
  • it外包工作怎么样seo网络运营
  • 郑州专业建站报价yandex搜索入口