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

vs做网站出现显示bug成都网站制作费用

vs做网站出现显示bug,成都网站制作费用,b2b模式的典型电商平台代表,工商局网站年检怎么做上一篇文章只实现了operator操作符重载&#xff0c;由于运算符较多&#xff0c;该篇文章单独实现剩余所有的运算符重载。继续以Date类为例&#xff0c;实现运算符重载&#xff1a; 1.Date.h #pragma once#include <iostream> #include <assert.h>using namespace …

在这里插入图片描述

上一篇文章只实现了operator==操作符重载,由于运算符较多,该篇文章单独实现剩余所有的运算符重载。继续以Date类为例,实现运算符重载:
1.Date.h

#pragma once#include <iostream>
#include <assert.h>using namespace std;class Date
{
private:int _year;int _month;int _day;
public:void Print();Date(int yaer, int month, int day);bool operator<(const Date& d);bool operator<=(const Date& d);bool operator>(const Date& d);bool operator>=(const Date& d);bool operator==(const Date& d);bool operator!=(const Date& d);//单独的用一个函数把每个月多少天,封装起来int GetMonthDays(int year, int month){assert(month > 0 && month < 13);static int MonthDay[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };if (month==2&&(year % 4 == 0 && year % 100 != 0)){return 29;}return MonthDay[month];}Date& operator+=(int day);Date operator+(int day);Date& operator-=(int day);Date operator-(int day);//++d,前置++Date& operator++();//d++,后置++Date operator++(int);//前置--Date& operator--();//后置--Date operator--(int);//两个日期相减:d1-d2int operator-(const Date& d);
};

Date.cpp

#define _CRT_SECURE_NO_WARNINGS 1 
#include <stdio.h>#include "Date.h"void Date::Print()
{cout << _year << "/" << _month << "/" << _day << endl;
}Date::Date(int year=1, int month=1, int day=1)
{_year = year;_month = month;_day = day;
}
//   写好一个直接复用!!!
bool Date::operator<(const Date& d)
{if (_year < d._year){return true;}else if (_year == d._year){if (_month < d._month)return true;else if ((_month == d._month) && (_day < d._day))return true;elsereturn false;}elsereturn false;
}bool Date::operator==(const Date& d)
{if ((_year == d._year) && (_month == d._month) && (_day == d._day))return true;elsereturn false;
}bool Date::operator<=(const Date& d)
{return *this == d || *this < d;
}bool Date::operator>(const Date& d)
{return !(*this <= d);
}bool Date::operator>=(const Date& d)
{return (*this > d || *this == d);
}bool Date::operator!=(const Date& d)
{return !(*this == d);
}Date& Date::operator+=(int day)
{_day += day;//先加//这里是while,因为如果是if的话,如果一次加了很大的数据减一次不一定能减得完!!!while(_day > GetMonthDays(_year, _month)){_day -= GetMonthDays(_year, _month);++_month;if (_month == 13){++_year;_month = 1;}}return *this;
}Date Date::operator+(int day)
{Date tmp=*this;tmp += day;return tmp;
}Date& Date::operator-=(int day)
{_day -= day;while (_day <= 0){--_month;if (_month == 0){--_year;_month = 12;}_day += GetMonthDays(_year, _month);}return *this;
}Date Date::operator-(int day)
{Date tmp = *this;tmp -= day;return tmp;
}Date& Date::operator++()
{return *this += 1;
}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;
}
//日期-日期,计算两个日期之间相差多少天int Date::operator-(const Date& d)
{int flag = 1;Date max = *this;Date min = d;if (*this < d){//赋值为-1的原因:因为这个函数是有顺序的d1-d2,如果遇到d1<d2,也就是小减大,最终返回的结果是个负数,所以说这里要变成-1。flag = -1;max = d;min = *this;}//定义一个变量int n = 0;// 用循环算两个日期中间的差值while (min != max){++min;++n;}return n * flag;
}

3.Test.cpp

#define _CRT_SECURE_NO_WARNINGS 1 
#include <stdio.h>
#include "Date.h"int main()
{Date d1(2024, 2, 15);Date d2 = d1 + 20;d1.Print();d2.Print();bool ret=d1 > d2;if (ret){d1.Print();}d2 += 100;d2.Print();d2 -= 100;d2.Print();Date d3 = d2 - 10;d3.Print();Date d4(2024, 1, 29);Date d5(2024, 8, 1);cout << d5 - d4 << endl;++d5;d5.Print();d5++;d5.Print();--d5;d5.Print();d5--;d5.Print();return 0;
}
http://www.ds6.com.cn/news/6197.html

相关文章:

  • 衢州网站建设网络营销方法和手段
  • 南京网站制作有限公司网站建设推广专家服务
  • 网络营销的8个基本职能免费下载优化大师
  • 南和网站建设市场调研报告怎么写的
  • 哪些网站可以做外贸seo排名哪家有名
  • 安阳做网站二级域名网站查询入口
  • 在线制作二维码网站创网站永久免费建站
  • 做百度手机网站优化点什么软件可以优化关键词
  • seo实战密码第三版pdf下载青岛seo杭州厂商
  • 和两个黑人同时做网站百度推广费用怎么算
  • 皖icp合肥网站建设中国国家培训网官网查询
  • Pk10网站建设多少钱推广优化方案
  • 做网站需要提供哪些信息推广软件排行榜前十名
  • 中国网站建设公司百强网上怎么免费推广
  • 最优做网站江西省seo
  • 做网站还需要搜狗吗站长工具国色天香
  • 江门市网站建设郴州seo网络优化
  • 西宁网站建设价格广告公司取名字参考大全
  • t型布局网站怎么做个人网页在线制作
  • 成都网站建设电话咨询百度 营销推广怎么收费
  • 吴彦祖做的艺术家网站军事新闻 今日关注
  • 做网站资料准备什么搜索引擎营销原理
  • 做短租公寓民宿网站网络优化公司有哪些
  • 张家口做网站哪家好视频号关键词搜索排名
  • 建设银行海门支行网站百度关键词优化推广
  • 高端网站建设公司好吗免费下载百度一下
  • 武汉网站设计站建设南昌seo推广
  • 北京网站制作公司飞沐南和网站seo
  • 关于网站建设申请seo外链优化
  • 丹阳企业网站制作图片外链