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

网站建设一百万网页设计实验报告心得和总结500字

网站建设一百万,网页设计实验报告心得和总结500字,安卓网站开发前景,中国互联网公司排名2023日期类的实现 一#xff0c;声明二#xff0c;函数成员定义2.1构造函数2.2获取月份天数2.3比较运算符2.3.1等于和大于2.3.2其他 2.4计算运算符2.4.1 2.4.2-- 2.5日期-日期 一#xff0c;声明 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 || _month12 || _day1 || _dayGetMonthDay(_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 !(*thisy); } 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 (_day0){_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.laogonggong.com/news/126075.html

相关文章:

  • 阿里云做网站步骤怎样黑公司的网站
  • 网站建立不安全怎么取消简易手机站
  • 建网站 3年服务器如何推广平台
  • 哪有做网站的定单论坛推广的特点
  • 360免费建站不要钱小型深圳网站页面设计
  • 024 网站推广做网站需要什么样的服务器
  • 有网站建wap南京小程序建设公司
  • 怎么做淘宝一样的网站营销企业网站建设步骤
  • 快速建设企业网站软件营销网站建设
  • 网站域名列表wordpress 资料
  • 建设网站浩森宇特网站开发包括什么软件
  • 公司网站建设需要多少钱近10天的时政新闻
  • 重庆网站制作福州企业网站推广的首选办法是
  • 烟台公司建网站个体工商户是否能够做网站
  • 广告公司网站建设方案电影资源网站建设
  • 做微网站的公司网站的中英文切换怎么做的
  • 网站建设 app开发 图片做淘宝客网站要备案吗
  • 淘宝客网站推广工具成都旅游公司
  • 上海专门做培训的网站手机新款上市
  • 导航网站模板免费个人制作的网站模板
  • 顺德网站制作案例价格wordpress网站不收录
  • 网站推广的措施有哪些视频网站系统开发
  • 网站建设结论与改进市场营销策略有哪些
  • 长春能开发网站的公司p2p网站建设公司
  • 重庆建设集团网站首页开发公司挖出的沙子归谁
  • 国外优秀flash网站网站建设与用户需求分析
  • 网站服务器配置参考指南高端人才招聘网站排名
  • 网站建设主要包括那些部分wordpress story 模板
  • 一元夺宝网站开发不同接入商备案网站
  • 收费小说网站怎么做佛山网站设计特色