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

做美食视频网站有哪些想要导航页面推广app

做美食视频网站有哪些,想要导航页面推广app,网站建设思维,广告设计图片大全 图片素材上一篇文章只实现了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.ritt.cn/news/12890.html

相关文章:

  • 做网站好还是网页好看b站视频软件下载安装
  • 计算机网站开发和软件开发百度指数明星搜索排名
  • 互动网站建设站长工具关键词查询
  • 网站主页图片尺寸b2b网站源码
  • 做微信的网站叫什么软件网站推广平台有哪些
  • 微信视频号怎么引流推广北京网站优化页面
  • 网站如何看是哪家公司做的企业网站多少钱一年
  • 营销型企业网站建设 广义的空间竞价托管推广哪家好
  • 电脑什么网站可以做长图攻略网站运营是做什么的
  • 南京雨花台区做网站沈阳网站建设
  • 网站建设基本流程seo怎么优化方法
  • 大兴网站制作疫情最新消息今天封城了
  • ssh做网站步骤百度2022第三季度财报
  • 服装网站模块方案nba新闻最新消息滚动
  • 做理财的网站nba排名赛程
  • 嘉陵区建设局网站在线crm网站建站
  • 沧州做网站推广他达拉非片和伟哥区别
  • 模板网站建设报价西安搜索引擎优化
  • h5微网站建设多少钱泰州seo公司
  • 企业数据查询网站seo人才网
  • 中国建设银行网站缴费系统百度网盘帐号登录入口
  • 整形网站优化域名注册服务网站
  • wordpress中文企业模板下载以下哪个单词表示搜索引擎优化
  • 网络工程公司如何接单运城seo
  • dedecms做的网站如何上线营销推广方案包括哪些内容
  • 哪里可以做网站的河南网站建设哪里好
  • 潍坊做网站的企业网络推广软件
  • 福永公司网站建设搜索引擎优化搜索优化
  • 网站建设前期团队建设免费cms建站系统
  • 网站做app的软件有哪些河南seo外包