📄 l6_4.cpp
字号:
#include <iostream.h>
#include <math.h>
class CPoint
{
public:
CPoint(int x=0, int y=0)
{
X=x;
Y=y;
cout << " CPoint 构造函数被调用" << endl;
};
CPoint(CPoint &p);
int GetX()
{
return X;
}
int GetY()
{
return Y;
}
private:
int X,Y;
};
CPoint::CPoint(CPoint &p)
{
X = p.X;
Y = p.Y;
cout << " CPoint 拷贝构造函数被调用" << endl;
cout << "(" << X << "," << Y << ")" << endl;
}
class CLine
{
public:
CLine(CPoint p1, CPoint p2);
float GetDistance();
private:
CPoint start;
CPoint end;
};
CLine::CLine(CPoint p1, CPoint p2): start(p1), end(p2)
{
cout << "CLine 构造函数被调用" << endl;
}
float CLine::GetDistance()
{
double x = double (end.GetX() - start.GetX() );
double y = double (end.GetY() - start.GetY() );
return (float) sqrt(x*x + y*y );
}
void main()
{
CPoint p1(1,1), p2(4,5);
CLine l(p1, p2);
cout << "The distance is :";
cout << l.GetDistance() << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -