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

廊坊营销型网站建设wordpress get_users

廊坊营销型网站建设,wordpress get_users,销量不高的网站怎么做,手机网站 生成app​#x1f47b;内容专栏#xff1a; C/C编程 #x1f428;本文概括#xff1a; C实现日期类。 #x1f43c;本文作者#xff1a; 阿四啊 #x1f438;发布时间#xff1a;2023.9.7 对于类的成员函数的声明和定义#xff0c;我们在类和对象上讲到过#xff0c;需要进行… ​内容专栏 C/C编程 本文概括 C实现日期类。 本文作者 阿四啊 发布时间2023.9.7 对于类的成员函数的声明和定义我们在类和对象上讲到过需要进行声明和定义分离。 一些需要使用的接口函数声明我们放入到Date.h文件中#include iostream using namespace std;class Date {public://构造函数Date(int year 1, int month 1, int day 1);//拷贝构造函数Date(const Date d);//析构函数//~Date(); //日期类可以不写//打印日期void Print()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;bool operator!(const Date d) const;//赋值运算符重载Date operator(const Date d);//日期 天数Date operator(int day);//日期 天数Date operator(int day) const;//日期 - 天数Date operator-(int day);//日期 - 天数Date operator-(int day) const;//获取当月天数int GetMonthDay(int year, int month) const;//前置Date operator();//后置Date operator(int);//前置--Date operator--();//后置--Date operator--(int);//日期 - 日期 返回天数int operator-(const Date d) const;private:int _year;int _month;int _day; };下面我们对一些日期接口函数的实现 实现于Date.cpp文件中一、构造函数、拷贝构造以及日期的打印 #include date.h //构造函数 Date::Date(int year, int month, int day) {_year year;_month month;_day day;//检查日期是否合法if (month 1 || month 12 || day 1 || day GetMonthDay(year, month)){cout 非法日期 endl;//exit(-1);} } Date::Date(const Date d) {_year d._year;_month d._month;_day d._day; } //Date::~Date() //{ // cout ~Date() endl; //} void Date::Print() const {cout _year 年 _month 月 _day 日 endl; }二、赋值运算符重载函数 //赋值运算符重载 Date Date::operator(const Date d) {if (this ! d){_year d._year;_month d._month;_day d._day;}return *this; }三、运算符重载 比较运算符重载 我们写一个operator 运算符重载函数和一个 operator 运算符重载函数即可其他直接复用就行。 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;}else{return false;} } 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) || (*this d); } bool Date::operator(const Date d) const {return !(*this d); } bool Date::operator(const Date d) const {return (*this d) || (*this d); } bool Date::operator!(const Date d) const {return !(*this d); }日期 ± 天数、日期 - 日期 获取当前月份的天数 首先我们需要写一个获取当月的天数GetMonthDay()函数以便于后面用日期 ± 天数运算。 //获取当月天数 int Date::GetMonthDay(int year, int month) const {static int MonthDayArray[13] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };//判断是否为闰年(先判断是否为2月)if (month 2 ((year % 4 0 year % 100 ! 0) || (year % 4 0))){return 29;}return MonthDayArray[month]; }日期 天数 与 日期 天数 //日期 天数 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){_year;_month 1;}}return *this; } //日期 天数 Date Date::operator(int day) const {Date tmp(*this);tmp day;return tmp; } 日期 天数 //Date Date::operator(int day) //{ // Date tmp(*this); // tmp._day day; // // while (tmp._day GetMonthDay(tmp._year, tmp._month)) // { // //月进位 // tmp._day - GetMonthDay(tmp._year, tmp._month); // tmp._month; // if (tmp._month 13) // { // tmp._year; // tmp._month 1; // } // } // // return tmp; //} // 日期 天数 //Date Date::operator(int day) //{ // *this *this day; // return *this; //}日期 - 天数 与 日期 - 天数 我们知道了先写operator再写operator直接复用即可这种方法更优所以我们日期减去天数也是实现operator-再实现operator- //日期 - 天数 Date Date::operator-(int day) {if (day 0){return *this -day;}_day - day;while (_day 0){_month--;if (_month 0){_year--;_month 12;}_day GetMonthDay(_year, _month);}return *this; }//日期 - 天数 Date Date::operator-(int day) const {Date tmp(*this);tmp - day;return tmp; }自增 和 自减 重载 C规定前置和后置都是一元运算符为了让前置与后置形成能正确重载后置重载时多增加了一个int类型的参数与前置构成函数重载以区分前置 //前置 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; }日期 - 日期 // d1 - d2 int Date::operator-(const Date d) const {//默认认为左边日期大Date max *this;Date min d;int flag 1;//为1返回正数-1返回负数int count 0;//统计天数//不成立则交换if (*this d){max d;min *this;flag -1;}//while(min max)while (min ! max){min;count;}return count * flag; }四、全局函数实现流插入流提取 date.h 流插入流提取重载函数的声明/*不能重载成成员函数否则会导致参数不匹配因为this指针永远占据第一个位置无法进行流插入提取操作。*/ //流插入 ostream operator(ostream out, const Date d); //流提取 istream operator(istream in, Date d);如果重载成成员函数那么成员函数的第一个参数永远是隐藏的this指针成员函数中只能利用out _year _month _day的顺序但是在调用时 (d1为日期类对象)d1 cout只能这么写虽然可以但是很别扭不符合使用习惯和价值。所以我们需要实现成全局函数才可以。 但是写成全局函数会访问类的成员变量我们可以利用友元或者将成员变量封装成成员函数解决。 date.cpp 流插入流提取重载函数的实现/*不能重载成成员函数否则会导致参数匹配因为this指针永远占据第一个位置无法进行流插入提取操作。*/ //涉及访问私有成员变量可以利用友元或者将成员变量封装成Get成员函数 //流插入 ostream operator(ostream out, const Date d) {out d._year 年 d._month 月 d._day 日 endl;return out; } //流提取 istream operator(istream in, Date d) {in d._year d._month d._day; }
http://wiki.neutronadmin.com/news/171173/

相关文章:

  • 网站建设需要域名还有什么网站建设代码怎么写
  • 建站长沙新网站怎么做才能可以在百度上搜索到
  • 未来做那个网站致富在线做投资网站
  • 87网站建设工作室汕头网站推广制作怎么做
  • 中学网站建设工作实施方案六安市建设网站市场信息价
  • 青岛网站建设哪家权威百度资源搜索资源平台
  • wordpress 网站赏析建设教育网站
  • 免费 微网站洛阳最新消息
  • 大庆市住房与城乡建设局网站网页开发三件套
  • 中为网站建设深圳市龙岗区住房和建设局
  • 个性化网站定制价格泰安网站开发哪家便宜
  • h5说 网站手机网站模板 html5 下载工具
  • 网站怎么不花钱做排名 知乎个人做网站多少钱
  • 网站建设公众号青岛建个网站多少钱
  • 辽宁省建设厅官方网站开发区邮编
  • iis 网站权限wordpress怎么增加按钮
  • 滨州市住房和城乡建设厅网站制作一个网站需要注意什么
  • 湖北网站推广方案留言板网页模板
  • 网站建立与推广中职学校网站建设方案
  • 网站显示图片标记万网域名查询接口
  • 建设局网站投诉开发商赣州做网站的公司有哪家
  • 国内优秀网站设计欣赏平邑网站定制
  • 女装市场网站建设费用评估查询网站有没有备案
  • 网站推广代运营wordpress 建站视频
  • 网站设计的提案想注册一个设计网站吗
  • 营销网站制作流程英文网站建设比较好
  • 服装代销的网站源码佛山营销型建设网站
  • wordpress建站资源网站模块分类
  • 淘宝上做淘宝客的网站jqueryui做的网站
  • 网站建设类的论文题目qq网页注册入口