1> 思维导图

2> 整理代码
- #include
-
- using namespace std;
-
- class Person
- {
- friend const Person operator+(const Person &L, const Person &R);
- friend const Person operator-(const Person &L, const Person &R);
- friend const Person operator*(const Person &L, const Person &R);
- friend const Person operator/(const Person &L, const Person &R);
- friend const Person operator%(const Person &L, const Person &R);
-
-
- friend bool operator>(const Person &L, const Person &R);
- friend bool operator>=(const Person &L, const Person &R);
- friend bool operator<(const Person &L, const Person &R);
- friend bool operator<=(const Person &L, const Person &R);
- friend bool operator==(const Person &L, const Person &R);
- friend bool operator!=(const Person &L, const Person &R);
-
-
- friend Person &operator+=(Person &L,const Person &R);
- private:
- int a;
- int b;
- public:
- Person(){}
- Person(int a, int b):a(a),b(b)
- {}
-
- void show()
- {
- cout << " a = " << a << " b = " << b << endl;
- }
-
- };
-
-
-
- //全局函数实现+运算符重载
- const Person operator+(const Person &L, const Person &R)
- {
- Person temp;
- temp.a = L.a + R.a;
- temp.b = L.b + R.b;
- return temp;
- }
-
- //全局函数实现-运算符重载
- const Person operator-(const Person &L, const Person &R)
- {
- Person temp;
- temp.a = L.a - R.a;
- temp.b = L.b - R.b;
- return temp;
- }
-
- //全局函数实现*运算符重载
- const Person operator*(const Person &L, const Person &R)
- {
- Person temp;
- temp.a = L.a * R.a;
- temp.b = L.b * R.b;
- return temp;
- }
-
- //全局函数实现/运算符重载
- const Person operator/(const Person &L, const Person &R)
- {
- Person temp;
- temp.a = L.a / R.a;
- temp.b = L.b / R.b;
- return temp;
- }
-
- //全局函数实现%运算符重载
- const Person operator%(const Person &L, const Person &R)
- {
- Person temp;
- temp.a = L.a % R.a;
- temp.b = L.b % R.b;
- return temp;
- }
-
- //全局函数实现>号运算符重载
- bool operator>(const Person &L, const Person &R)
- {
- if(L.a>R.a && L.b>R.b)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
-
- //全局函数实现>=号运算符重载
- bool operator>=(const Person &L, const Person &R)
- {
- if(L.a>=R.a && L.b>=R.b)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
-
- //全局函数实现<号运算符重载
- bool operator<(const Person &L, const Person &R)
- {
- if(L.a
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- //全局函数实现<=号运算符重载
- bool operator<=(const Person &L, const Person &R)
- {
- if(L.a<=R.a && L.b<=R.b)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- //全局函数实现==号运算符重载
- bool operator==(const Person &L, const Person &R)
- {
- if(L.a==R.a && L.b==R.b)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- //全局函数实现!=号运算符重载
- bool operator!=(const Person &L, const Person &R)
- {
- if(L.a!=R.a && L.b!=R.b)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- //全局函数实现+=号运算符重载
- Person &operator+=(Person &L,const Person &R)
- {
- L.a += R.a;
- L.b += R.b;
-
-
- return L;
-
-
- }
-
-
- int main()
- {
- Person p1(100,100);
- Person p2(50,50);
-
- Person p3 = p1 + p2;
- p3.show();
-
- Person p4 = p1 - p2;
- p4.show();
-
- Person p5 = p1 * p2;
- p5.show();
-
- Person p6 = p1 / p2;
- p6.show();
-
- Person p7 = p1 % p2;
- p7.show();
-
- if(p3>p2)
- {
- cout << "p3>p2" << endl;
- }
-
- if(p3>=p2)
- {
- cout << "p3>=p2" << endl;
- }
-
- if(p3
- {
- cout << "p3
<< endl; - }
-
- if(p3<=p2)
- {
- cout << "p3<=p2" << endl;
- }
-
- if(p3==p2)
- {
- cout << "p3==p2" << endl;
- }
-
- if(p3!=p2)
- {
- cout << "p3!=p2" << endl;
- }
-
- p3+=p2;
- p3.show();
-
-
- return 0;
- }
-
相关阅读:
Java的基本组成部分是什么?
基于Java实现一个简单的YACC
独立站引流新玩法
使用数组方法打印出 1 - 10000 之间的所有对称数。例如:121、1331等
Dubbo订阅发布的实现原理
第2章 Spring Boot实践,开发社区登录模块(下)
C++基础知识(十九)--- 函数对象
使用iso镜像包制作离线本地镜像源(本地yum源)
由于找不到vcruntime140_1.dll,无法继续执行代码重新安装程序可能会解决此问题
物联网技术栈之网关技术
-
原文地址:https://blog.csdn.net/m0_72133977/article/details/133754954