Problem Description
建立一个二维坐标系的类TwoCoor,用x、y表示坐标值,计算两坐标点间的距离
//你的代码将被嵌在这里
int main(){
TwoCoor p1(3,0),p2(0,4);
cout<<dist(p1,p2);
return 0;
}
Sample Output
5
#include <iostream>
using namespace std;
#include <cmath>
class TwoCoor
{
public:
TwoCoor(double x, double y)
{
m_x = x;
m_y = y;
}
double m_x;
double m_y;
};
double dist(TwoCoor p1, TwoCoor p2)
{
double a = sqrt(pow((p1.m_x - p2.m_x),2) + pow((p1.m_y - p2.m_y),2));
return a;
}