Point类

本文档展示了如何在C++中定义一个Point类,并重载`+=`和`-=`运算符,使得可以进行点的坐标相加和相减操作。通过示例输入输出展示了如何使用这些重载的运算符进行点的运算。
摘要由CSDN通过智能技术生成

//编写Point类,重载+=和-=运算符,能够完成p1+=p2和p1-=p2的功能。
//【输入形式】int ,int
//【输出形式】
//【样例输入】1 2 3 4
//【样例输出】 p1=(1,2)
//             p2=(3,4)
//             p3=(4,6)
//             p4=(-2,-2)
#include <iostream>
using namespace std;
class Point
{
  public:
    double x;
    double y;
    Point();//构造函数
    friend Point operator+=(Point &a,Point &b);//重载+=运算符
    friend Point operator-=(Point &a,Point &b);//重载-=运算符
    friend istream& operator>>(istream&in,Point &a);//重载流插入运算符
    friend ostream& operator<<(ostream&out,Point &a);//重载流提取运算符
};
Point::Point()
{
    x=0;
    y=0;
}
Point operator+=(Point &a,Point &b)
{
    a.x+=b.x;
    a.y&

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值