首页 > 其他分享 >多态性12

多态性12

时间:2023-04-21 20:00:11浏览次数:36  
标签:p2 12 const cout Point 多态性 p1 operator

#include<iostream>
using namespace std;
class Point{
public:
Point(){
x=0;
y=0;
}
Point(float x1,float y1){
x=x1;
y=y1;
}
friend Point operator+(const Point &p1,const Point &p2);
Point& operator=(const Point &pd);
friend ostream & operator<<(ostream &out,const Point &p);

~Point(){}
private:
float x;
float y;
};
Point operator+(const Point& p1,const Point& p2){
Point p3;
p3.x=p1.x+p2.x;
p3.y=p1.y+p2.y;
return p3;
}
Point & Point::operator=(const Point &pd){
x=pd.x;
y=pd.y;
return *this;
}
ostream & operator<<(ostream &out,const Point &p){
out<<"("<<p.x<<","<<p.y<<")";
return out;
}
int main()
{
Point p1(2,3);
Point p2(5,6);
Point p3(4,5);
Point p4(5,2);
Point p5;
cout<<"p1初始坐标:"<<p1<<endl<<endl;
cout<<"p2初始坐标:"<<p2<<endl<<endl;
cout<<"p3初始坐标:"<<p3<<endl<<endl;
cout<<"p4初始坐标:"<<p4<<endl<<endl;
p5=p1+p2;
cout<<endl<<"p1+p2="<<p5;
p5=p3+p4;
cout<<endl<<"p3+p4="<<p5;
return 0;
}

标签:p2,12,const,cout,Point,多态性,p1,operator
From: https://www.cnblogs.com/yuanxinglan/p/17341608.html

相关文章

  • 多态性13
    #include<iostream>usingnamespacestd;classBaseClass{ public: BaseClass(){ cout<<"constructBaseClass"<<endl; } ~BaseClass(){ cout<<"destructBaseClass"<<endl; }};classDerived:publicBaseClass{ p......
  • The 1st Universal Cup. Stage 12: Ōokayama
    G容斥完之后发现要求一个m次多项式的n次方,并且得到\(n\timesm\)项。原本很sb地直接套了个多项式LnExp上去(即使知道大概率过不了),然后狂TLE。。。其实但凡从常数的角度分析,Exp的常数有14倍,已经比\(log(m)\)大了,所以不如写快速幂,然后写着就会发现卷积的长度总和其实是\((n\times......
  • 多态性12
    #include<iostream>#definePI3.14usingnamespacestd;classShape{public:    Shape(){cout<<"shape构造"<<endl;}    virtualdoublegetArea()=0;    virtualdoublegetPerim()=0;    ~Shape(){cout<<"shape析构"<......
  • 12、freestyle风格的流水线作业回顾
    freestyle风格的流水线作业回顾回顾:流水线作业:FreestyleJob:Jenkins1.x,开放式UI,手动MavenJobPipelineJob:Jenkins2.x,开放式编码,定义流水线maven工程spring-boot-helloworld克隆、构建、......
  • day 12 存钱问题
    1.找到相关年份的限制条件(年总和不可以超过20);2.根据限制遍历所有情况(采用循环);3.定义Max记录最大值;4.输出 #include<iostream>usingnamespacestd;intx8,x5,x3,x2,x1;doublef(intnum,doublet,intm){doublesum=1;for(inti=0;i<m;i++){sum*=(1+nu......
  • 洪君:mybatis plus012:增删改查 洪君
    plus的pom依赖:替代原mybatis<!--mybatisplus--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus</artifactId><version>2.1.9</version></d......
  • 求出11-12+13-14…
    求出1/1-1/2+1/3-1/4…..1/100的和vari=1;(倒数和)首先分析题目,可以找出规律,分母为奇数时为累加,分母为偶数时累减。由此可以写出循环逻辑<script>letsum=0 //首先定义一个变量用来存放加减结果for(leti=1;i<=100;i++){if(i......
  • JMeter入门教程(12) --集合点
    文章目录1.任务背景2.任务目标3.任务实操1.任务背景JMeter中集合点是通过定时器SynchronizingTimer来实现的,本篇针对集合点展开详细介绍2.任务目标掌握基于JMeter性能测试脚本开发——集合点3.任务实操添加SynchronizingTimer,右击请求,选择添加>定时器>SynchronizingTimer......
  • 银河麒麟高级服务器操作系统V10 SP3安装kafka_2.12-2.3.1
    银河麒麟高级服务器操作系统V10SP3安装kafka_2.12-2.3.1 1.安装环境设置1关闭Selinux12345678910111213141516171819[root@localhost~]#vim/etc/selinux/config #Thisfilecontrolsthestate of SELinux on thesystem.#SELI......
  • 51nod 1212 无向图最小生成树(最小生成树)
    1212 无向图最小生成树基准时间限制:1 秒空间限制:131072 KB分值: 0 难度:基础题 收藏 关注Input第1行:2个数N,M中间用空格分隔,N为点的数量,M为边的数量。(2 <= N <= 1000, 1 <= M <= 50000)第2 - M + 1行:每行......