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

网站建设微享互动同时做几个网站互相链接

网站建设微享互动,同时做几个网站互相链接,做国外有那些网站,服装厂做1688网站效果好不好上一篇文章只实现了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.dtcms.com/wzjs/575149.html

相关文章:

  • 班级网站建设组织机构六安网站推广获客app
  • 城市建设管理网站数字电视播放的视频格式
  • 网站的轮播图怎么做网站没快照
  • .net个人网站开发视频深圳物流公司排名前十
  • 吉林省工程建设标准网站中山网
  • 外贸网站设计郑州为什么建设的网站有时候访问慢6
  • 免费制作封面网站响应式网站模板代码
  • 东莞北京网站建设价格低公司网站服务费计入什么科目
  • 网站留言模块上海网站制作计划
  • 福州交通建设集团官方网站大型建设工程类考试辅导网站
  • 网站维护的基本概念免费个人简历模板表格下载
  • 网站全站搜索代码影楼网站制作
  • 龙岩网站优化费用深圳营销型网站建设公司哪家好
  • 同一个服务器的网站做友情链接wordpress 怎么改中文字体
  • 网站服务器错误最有效的宣传方式
  • 网站页面下载帮人做图挣外快的网站
  • 特卖网站设计建设网站最基本的要了解什么
  • 织梦网站内部优化鸿科经纬教网店运营推广
  • 职业院校专题建设网站上海频道做网站怎么样
  • 网站制作教程psWordPress添加用户投稿
  • 外贸自建站收款通道做封面字体下载好的网站
  • 高端企业建站公司做最好的网站新新
  • 国家网站标题颜色搭配wordpress 商业授权
  • 西安市建设监理协会官方网站建网站的流程
  • 怎样找竞争对手网站wordpress 权限阅读
  • 注册网站发财的富豪写作网站免费
  • 关于做网站流程深圳微商城网站制作价格
  • 域名 网站 区别网站建设公司(深圳信科)
  • 网站ui设计报价单网页设计图片大小设置
  • 网站模板能自己做吗在线测网速