˫Ŀ
来自「C语言相关程序」· 代码 · 共 105 行
TXT
105 行
#include<iostream.h>
class point
{
int x,y;
public:
point()
{
x=y=0;
}
point (int i,int j)
{
x=i;
y=j;
}
point (point &);
~point(){}
void offset(int,int);
void offset(point);
bool operator==(point);
bool operator!=(point);
void operator+=(point);
void operator-=(point);
point operator+(point);
point operator-(point);
int getx(){return x;}
int gety(){return y;}
void disp()
{
cout<<"("<<","<<")"<<endl;
}
};
point::point(point &p)
{
x=p.x;
y=p.y;
}
void point::offset(int i,int j)
{
x+=i;
y+=j;
}
void point::offset(point p)
{
x+=p.getx();
y+=p.gety();
}
bool point::operator==(point p)
{
if(x==p.getx()&&y==p.gety())
return 1;
else
return 0;
}
bool point::operator!=(point p)
{
if(x!=p.getx()||y!=p.gety())
return 1;
else
return 0;
}
void point::operator+=(point p)
{
x+=p.getx();
y+=p.gety();
}
void point::operator-=(point p)
{
x-=p.getx();
y-=p.gety();
}
point point::operator+(point p)
{
this->x+=p.x;
this->y+=p.y;
return *this;
}
point point::operator-(point p)
{
this->x-=p.x;
this->y-=p.y;
return *this;
}
void main()
{
point p1(2,3),p2(3,4),p3(p2);
cout<<"1:";
p3.disp();
p3.offset(10,10);
cout<<"2:";
p3.disp();
cout<<"3:"<<(p2==p3)<<endl;
cout<<"4:"<<(p2!=p3)<<endl;
p3+=p1;
cout<<"5:";
p3.disp();
p3-=p2;
cout<<"6:";
p3.disp();
p3=p1+p3;
cout<<"7:";
p3.disp();
p3=p1-p2;
cout<<"8:";
p3.disp();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?