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

自己建立旅游的网站建设高端定制网站的特点

自己建立旅游的网站建设,高端定制网站的特点,怎么做国内网站吗,网站建设.c文章目录#x1f449;日期类介绍#x1f448;#x1f449;日期类实现#x1f448;#x1f4d5; 成员变量#x1f4d5; 构造函数#x1f4d5; 对应月份天数#x1f4d5; 赋值重载#x1f4d5; 比较运算符重载#x1f4d5; 计算 运算符重载#x1f449;源代码#x1… 文章目录日期类介绍日期类实现 成员变量 构造函数 对应月份天数 赋值重载 比较运算符重载 计算 运算符重载源代码Date.hDate.cpp日期类介绍 日期类是用来描述具体日期的涉及到 年、月、日当然也可以有多个日期之间的关系。 class Date {friend istream operator(istream in, Date d);friend ostream operator(ostream out,const Date d);public:int GetMonthDay(int year, int month);Date(int year 2023, int month 2, int day 3);bool operator(const Date d)const;bool operator!(const Date d)const;bool operator(const Date d)const;bool operator(const Date d)const;bool operator(const Date d)const;bool operator(const Date d)const;Date operator(const Date d);Date operator(int day);Date operator(int day);Date operator(); // 前置Date operator(int); // 后置 int 参数只是和前置 区分Date operator-(int day);Date operator-(int day);int operator-(const Date d)const;void operator(ostream out);void Print()const;private:int _year;int _month;int _day; };日期类实现 成员变量 private:int _year;int _month;int _day;构造函数 Date::Date(int year,int month, int day){assert(month 0 month 13);_year year;_month month;_day day;}对应月份天数 由于申明和定义分离申明是在 Date 这个命名空间里面的所以要用访问限定修饰符。 每个月天数是对应的可以用数组存储除了闰年的二月可以单独判断。 int Date::GetMonthDay(int year, int month) {assert(month 0 month 13);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;}else{return monthArray[month];} }赋值重载 要考虑一个情况就是自己赋值给自己这种情况什么都不用做所以直接用 if 语句跳过。 当然传参和传返回值都是引用提高效率。 Date Date::operator(const Date d){if (this ! d){_year d._year;_month d._month;_day d._day;}return *this;}比较运算符重载 实际只要写两个 和 当然 和 也可以其他的可以复用这两个。 bool Date::operator(const Date d)const{return _year d._year _month d._month _day d._day;}bool Date::operator!(const Date d)const{return !(*this d);}bool Date::operator(const Date d)const{if (_year d._year)return true;else if (_year d._year _month d._month)return true;else if (_year d._year (_month d._month) _day d._day)return true;return false;}bool Date::operator(const Date d)const{return *this d || *this d;}bool Date::operator(const Date d)const{return !(*this d);}bool Date::operator(const Date d)const{return !(*this d);}计算 运算符重载 如下 重载返回值是 Date 是为了方便 d d1x 这样的情况d1 先加上 x天的日期赋值给 d 。 的重载可以直接复用 。因为例如 d1 99 是返回 d1 这个日期 99天之后的具体日期但是 d1 本身不会改变所以返回值绝对不可以是 d1 的引用而要是一个另一个变量。返回该变量的时候要创建临时变量并进行拷贝构造。 但是如果先写再让 复用 就会导致 也要进行拷贝构造有小号。 另外- 和 - 的重载也和上面类似的原理- 复用 - 而对于后置编译器会自动传一个int 类型的参数我们不用去理会。 计算两个日期的天数有了前面的重载就很容易只需要日期小的一直直到和另一个日期相等即可。 Date Date::operator(int day) {if (day 0){*this - -day;return *this;}_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; }Date Date::operator() {*this 1;return *this; }// 调用后置 的时候编译器自动传一个 int 类型的参数 Date Date::operator(int) {Date tmp(*this);*this 1;return tmp; }Date Date::operator-(int day) {if (day 0){*this -day;return *this;}_day - day;while (_day 0){_month - 1;if (_month 0){_year - 1;_month 12;}_day GetMonthDay(_year, _month);}return *this; }Date Date::operator-(int day) {Date tmp *this;tmp - day;return tmp; }int Date::operator-(const Date d)const {Date max *this;Date min d;int flag 1;if (max min){max d;min *this;flag -1;}int ret 0;while (max ! min){min;ret;}return ret*flag;}源代码 Date.h #pragma once #includeiostream #includeassert.h #includestdlib.h using namespace std;class Date {friend istream operator(istream in, Date d);friend ostream operator(ostream out,const Date d);public:int GetMonthDay(int year, int month);Date(int year 2023, int month 2, int day 3);//Date(const Date d);bool operator(const Date d)const;bool operator!(const Date d)const;bool operator(const Date d)const;bool operator(const Date d)const;bool operator(const Date d)const;bool operator(const Date d)const;Date operator(const Date d);Date operator(int day);Date operator(int day);Date operator(); // 前置Date operator(int); // 后置 int 参数只是和前置 区分Date operator-(int day);Date operator-(int day);int operator-(const Date d)const;void operator(ostream out);void Print()const;private:int _year;int _month;int _day; };// 使用内联函数 inline ostream operator(ostream out, const Date d) {cout d._year 年 d._month 月 d._day 日 endl;return out; }inline istream operator(istream in, Date d) {in d._year d._month d._day;return in; }Date.cpp #includeDate.h int Date::GetMonthDay(int year, int month) {assert(month 0 month 13);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;}else{return monthArray[month];} }Date::Date(int year,int month, int day){assert(month 0 month 13);_year year;_month month;_day day;}bool Date::operator(const Date d)const{return _year d._year _month d._month _day d._day;}bool Date::operator!(const Date d)const{return !(*this d);}bool Date::operator(const Date d)const{if (_year d._year)return true;else if (_year d._year _month d._month)return true;else if (_year d._year (_month d._month) _day d._day)return true;return false;}bool Date::operator(const Date d)const{return *this d || *this d;}bool Date::operator(const Date d)const{return !(*this d);}bool Date::operator(const Date d)const{return !(*this d);}Date Date::operator(const Date d){if (this ! d){_year d._year;_month d._month;_day d._day;}return *this;}void Date::Print()const{cout _year 年 _month 月 _day 日 endl;}Date Date::operator(int day) {if (day 0){*this - -day;return *this;}_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; }Date Date::operator() {*this 1;return *this; }// 调用后置 的时候编译器自动传一个 int 类型的参数 Date Date::operator(int) {Date tmp(*this);*this 1;return tmp; }Date Date::operator-(int day) {if (day 0){*this -day;return *this;}_day - day;while (_day 0){_month - 1;if (_month 0){_year - 1;_month 12;}_day GetMonthDay(_year, _month);}return *this; }Date Date::operator-(int day) {Date tmp *this;tmp - day;return tmp; }int Date::operator-(const Date d)const {Date max *this;Date min d;int flag 1;if (max min){max d;min *this;flag -1;}int ret 0;while (max ! min){min;ret;}return ret*flag;}void Date::operator(ostream out) {cout _year 年 _month 月 _day 日 endl; }
http://www.w-s-a.com/news/660298/

相关文章:

  • 南京江宁网站建设大学高校网站建设栏目
  • 模板网站建设明细报价表做网站第一
  • 公司网站建设系统软件开发 上海
  • 怎么让公司建设网站固安县建设局网站
  • 360免费建站官网入口手机网站建设设计
  • 商城网站建站系统dw如何做网页
  • 网站建设的公司收费我有网站 怎么做淘宝推广的
  • 网站建设策划书事物选题手机兼职app
  • html5 微网站模版wordpress博客速度很慢
  • 怎么做五个页面网站网络推广如何收费
  • 上虞宇普电器网站建设江西建筑人才网
  • 在吗做网站商城一个网站需要服务器吗
  • 先做网站再备案吗中山微网站建设报价
  • 树莓派可以做网站的服务器吗网站建设与设计ppt
  • 网站访问速度分析网站怎么做让PC和手机自动识别
  • 网站建设要考西宁网站建设多少钱
  • 网站开发公司东莞网站推广计划书具体包含哪些基本内容?
  • 素材天下网站惠州网站建设行业
  • 网站做a视频在线观看网站天津建站
  • 自己做的网站怎么链接火车头采集一个网站可以做几级链接
  • 济南网站制作哪家专业做网站怎样投放广告
  • 辽宁网站推广短视频运营培训学费多少
  • 拼多多网站怎么做翻译 插件 wordpress
  • 做网站运营的职业生涯规划wordpress分类显示图片
  • 网站建设与制作总结沈阳百度广告
  • 网站管理系统 手机会员制网站搭建wordpress
  • 做物品租赁网站清新wordpress主题
  • 优秀专题网站家居企业网站建设市场
  • 中山市有什么网站推广wordpress轻应用主机
  • 洗头竖鞋带名片改良授权做网站不贵整个世界