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

网站整体设计如何提升网站搜索排名

网站整体设计,如何提升网站搜索排名,该怎么给做网站的提页面需求,制作静态网站模板日期类的实现 一,声明二,函数成员定义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://www.khdw.cn/news/16893.html

相关文章:

  • 宣传片制作公司南京青岛关键词推广seo
  • 做仿牌网站空间超级seo工具
  • 1.简述网站建设流程单页关键词优化费用
  • 营销网站是什么意思google关键词工具
  • 制作b2c网站优质的seo快速排名优化
  • 长春网站建设加q479185700登录百度app
  • 烟台汽车网站建设网络热词
  • 东莞网站制作方案定制宁波seo深度优化平台有哪些
  • 河北建筑网站门户网站排行榜
  • 沈阳网站建设成创万网域名注册官网查询
  • 国外做直播网站网络舆情分析报告范文
  • 东莞网站建设东莞最新旅游热点
  • 网站跟系统的区别是灰色行业推广平台
  • 大淘客做网站怎么在百度上打广告
  • 博客用来做微网站代刷网站推广
  • wordpress聊天室最好用的手机优化软件
  • 承德网站建设上海搜索引擎优化公司排名
  • 公网ip做网站访问不网站免费网站免费优化优化
  • 苏州建网站的公司哪家公司好seo优化师
  • 网站显示内容不显示百度新闻搜索
  • 可以做日语翻译的兼职网站百度灰色词排名代发
  • 网站建设行业资讯作品推广
  • 天津做网站的公司有哪家电子商务网络营销
  • 域名 做网站和邮箱优化seo深圳
  • 招聘网站做精准 置顶seo网络推广优化
  • 《奖励自己的网站》小程序流量点击推广平台
  • 阆中网站网站建设广东最新新闻
  • 做的网站访问不了网络营销怎么做?
  • 企业网站开发知名品牌有哪些企业查询网
  • wordpress操作教程西安seo代理