10_10C++

X-mid

在这里插入图片描述

#include <iostream>
using namespace std;
class Kun
{//算术运算符friend const Kun operator+(const Kun &k1,const Kun &k2);friend const Kun operator-(const Kun &k1,const Kun &k2);friend const Kun operator*(const Kun &k1,const Kun &k2);friend const Kun operator/(const Kun &k1,const Kun &k2);//关系运算符friend bool operator==(const Kun &k1,const Kun &k2);friend bool operator>(const Kun &k1,const Kun &k2);friend bool operator<(const Kun &k1,const Kun &k2);friend bool operator!=(const Kun &k1,const Kun &k2);//赋值运算符friend Kun &operator+=(Kun &k1,const Kun &k2);friend Kun &operator-=(Kun &k1,const Kun &k2);friend Kun &operator*=(Kun &k1,const Kun &k2);friend Kun &operator/=(Kun &k1,const Kun &k2);private:int a;int b;
public:Kun(){}Kun(int a,int b):a(a),b(b){}void show(){cout << "a=" << a << endl << "b=" << b << endl;}//算术运算符
//    const Kun operator+( const Kun &k) const
//    {
//        Kun temp;
//        temp.a = a + k.a;
//        temp.b = b + k.b;
//        return temp;
//    }
//    const Kun operator-( const Kun &k) const
//    {
//        Kun temp;
//        temp.a = a - k.a;
//        temp.b = b - k.b;
//        return temp;
//    }
//    const Kun operator*( const Kun &k) const
//    {
//        Kun temp;
//        temp.a = a * k.a;
//        temp.b = b * k.b;
//        return temp;
//    }
//    const Kun operator/( const Kun &k) const
//    {
//        Kun temp;
//        temp.a = a / k.a;
//        temp.b = b / k.b;
//        return temp;
//    }
//    const Kun operator%( const Kun &k) const
//    {
//        Kun temp;
//        temp.a = a % k.a;
//        temp.b = b % k.b;
//        return temp;
//    }//关系运算符
//    bool operator==(const Kun &k) const
//    {
//        if(a == k.a && b == k.b)
//        {
//            return true;
//        }else
//            return false;
//    }
//    bool operator>(const Kun &k) const
//    {
//        if(a > k.a && b > k.b){
//            return true;
//        }else
//            return false;
//    }
//    bool operator<(const Kun &k) const
//    {
//        if(a < k.a && b < k.b){
//            return true;
//        }else
//            return false;
//    }
//    bool operator!=(const Kun &k) const
//    {
//        if(a != k.a && b != k.b){
//            return true;
//        }else
//            return false;
//    }//赋值运算符
//    Kun &operator+=(const Kun &k2)
//    {
//        a += k2.a;
//        b += k2.b;
//        return *this;
//    }
//    Kun &operator-=(const Kun &k2)
//    {
//        a -= k2.a;
//        b -= k2.b;
//        return *this;
//    }
//    Kun &operator=(const Kun &k2)
//    {
//      if(this!=&k2){
//            a = k2.a;
//            b = k2.b;
//      }
//        return *this;
//    }
//    Kun &operator*=(const Kun &k2)
//    {
//        a *= k2.a;
//        b *= k2.b;
//        return *this;
//    }
//    Kun &operator/=(const Kun &k2)
//    {
//        a /= k2.a;
//        b /= k2.b;
//        return *this;
//    }
};//算术运算符
const Kun operator+(const Kun &k1,const Kun &k2)
{Kun temp;temp.a = k1.a + k2.a;temp.b = k1.b + k2.b;return temp;
}
const Kun operator-(const Kun &k1,const Kun &k2)
{Kun temp;temp.a = k1.a - k2.a;temp.b = k1.b - k2.b;return temp;
}
const Kun operator*(const Kun &k1,const Kun &k2)
{Kun temp;temp.a = k1.a * k2.a;temp.b = k1.b * k2.b;return temp;
}
const Kun operator/(const Kun &k1,const Kun &k2)
{Kun temp;temp.a = k1.a / k2.a;temp.b = k1.b / k2.b;return temp;
}
//关系运算符
bool operator==(const Kun &k1,const Kun &k2)
{if(k1.a == k2.a && k1.b == k2.b){return true;}elsereturn false;
}
bool operator>(const Kun &k1,const Kun &k2)
{if(k1.a >k2.a && k1.b > k2.b){return true;}elsereturn false;
}
bool operator<(const Kun &k1,const Kun &k2)
{if(k1.a < k2.a && k1.b < k2.b){return true;}elsereturn false;
}
bool operator!=(const Kun &k1,const Kun &k2)
{if(k1.a != k2.a && k1.b != k2.b){return true;}elsereturn false;
}
//赋值运算符
Kun &operator+=(Kun &k1,const Kun &k2)
{k1.a += k2.a;k1.b += k2.b;return k1;
}
Kun &operator-=(Kun &k1,const Kun &k2)
{k1.a -= k2.a;k1.b -= k2.b;return k1;
}
Kun &operator*=(Kun &k1,const Kun &k2)
{k1.a *= k2.a;k1.b *= k2.b;return k1;
}
Kun &operator/=(Kun &k1,const Kun &k2)
{k1.a /= k2.a;k1.b /= k2.b;return k1;
}
int main()
{Kun k(10,10);Kun kk(10,10);Kun kkk = k + kk;kkk.show();if(kkk == kk){cout << "左右操作数想等" << endl;}else if(kkk > kk){cout << "左操作数大于右操作数" << endl;}else if(kkk < kk){cout << "左操作数小于右操作数" << endl;}else{cout << "不知道" << endl;}kkk+=kk;kkk.show();kkk-=kk;kkk.show();return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/130143.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[nltk_data] Error loading stopwords: <urlopen error [WinError 10054]

报错提示&#xff1a; >>> import nltk >>> nltk.download(stopwords) 按照提示执行后 [nltk_data] Error loading stopwords: <urlopen error [WinError 10054] 找到路径C:\\Users\\EDY\\nltk_data&#xff0c;如果没有nltk_data文件夹&#xff0c;在…

【算法|双指针系列No.4】leetcode11. 盛最多水的容器

个人主页&#xff1a;兜里有颗棉花糖 欢迎 点赞&#x1f44d; 收藏✨ 留言✉ 加关注&#x1f493;本文由 兜里有颗棉花糖 原创 收录于专栏【手撕算法系列专栏】【LeetCode】 &#x1f354;本专栏旨在提高自己算法能力的同时&#xff0c;记录一下自己的学习过程&#xff0c;希望…

解决:yarn 无法加载文件 “C:\Users\XXXXX\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本“ 的问题

1、问题描述&#xff1a; 报错的整体代码为&#xff1a; yarn : 无法加载文件 C:\Users\admin\AppData\Roaming\npm\yarn.ps1&#xff0c;因为在此系统上禁止运行脚本 // 整体的报错代码为 &#xff1a; yarn : 无法加载文件 C:\Users\admin\AppData\Roaming\npm\yarn.ps1&…

vue3学习(一)---新特性

文章目录 vue3和vue2的区别重写双向数据绑定优化Vdom性能瓶颈patch flag 优化静态树 FragmentTree shaking组合式API写法 vue3和vue2的区别 重写双向数据绑定 vue2 基于Object.defineProperty()实现vue3 基于Proxy proxy与Object.defineProperty(obj, prop, desc)方式相比有以…

[idekCTF 2022]Paywall - LFI+伪协议+filter_chain

[idekCTF 2022]Paywall 一、解题流程&#xff08;一&#xff09;、分析&#xff08;二&#xff09;、解题 二、思考总结 一、解题流程 &#xff08;一&#xff09;、分析 点击source可以看到源码&#xff0c;其中关键部分&#xff1a;if (isset($_GET[p])) {$article_content…

阶段六-Day02-Maven

一、学习Maven 使用Maven创建Web项目&#xff0c;并部署到服务器。 二、Maven介绍及加载原理 1. 介绍 Maven是使用Java语言编写的基于项目对象模型&#xff08;POM&#xff09;的项目管理工具。开发者可以通过一小段描述信息来管理项目的构建、报告和文档。 使用Maven可以…

LabVIEW玩转魔方

LabVIEW玩转魔方 使用LabVIEW创建一个3D魔方&#xff0c;并找出解谜题的秘密&#xff0c;给朋友留下深刻深刻的印象。游戏中内置的机制使每张脸都能独立转动&#xff0c;从而混合颜色。要解决难题&#xff0c;每个面必须是相同的纯色 魔方的奥秘在于它的简单性和不可解性。这是…

uni-app:服务器端数据绘制echarts图标(renderjs解决手机端无法显示问题)

效果 代码 <template><view click"echarts.onClick" :prop"option" :change:prop"echarts.updateEcharts" id"echarts" class"echarts"></view> </template><script>export default {data()…

设计模式 - 迭代器模式

目录 一. 前言 二. 实现 三. 优缺点 一. 前言 迭代器模式是一种行为型设计模式&#xff0c;它提供了一种统一的方式来访问集合对象中的元素&#xff0c;而不暴露集合内部的表示方式。简单地说&#xff0c;就是将遍历集合的责任封装到一个单独的对象中&#xff0c;我们可以按…

3D 生成重建004-DreamFusion and SJC :TEXT-TO-3D USING 2D DIFFUSION

3D 生成重建004-DreamFusion and SJC &#xff1a;TEXT-TO-3D USING 2D DIFFUSION 文章目录 0 论文工作1 论文方法1.1论文方法1.2 CFG1.3影响1.4 SJC 2 效果 0 论文工作 对于生成任务&#xff0c;我们是需要有一个数据样本&#xff0c;让模型去学习数据分布 p ( x ) p(x) p(x…

目前制造企业生产计划现状是什么?有没有自动化排产系统?

大家都知道&#xff0c;人的指挥中心是大脑&#xff0c;大脑对我们的发出各种各样的指令&#xff0c;告诉我们&#xff1a;“手”做什么事情&#xff0c;“眼睛”看什么地方&#xff0c;“耳朵”听什么声音&#xff0c;然后再将摸到的、看到的、听到的信息传递给大脑&#xff0…

大数据学习(1)-Hadoop

&&大数据学习&& &#x1f525;系列专栏&#xff1a; &#x1f451;哲学语录: 承认自己的无知&#xff0c;乃是开启智慧的大门 &#x1f496;如果觉得博主的文章还不错的话&#xff0c;请点赞&#x1f44d;收藏⭐️留言&#x1f4dd;支持一下博>主哦&#x…