问题及代码
ALL rights reserved.
*文件名称: 初学对象6
作者:李长鸿
*完成时间:2015.4.15
*问题描述: 阅读程序
*/
#include <iostream>
#include<cmath>
using namespace std;
class CPoint
{
private:
double x; // 横坐标
double y; // 纵坐标
public:
CPoint(double xx=0,double yy=0):x(xx),y(yy){}
//请继续写需要的代码
double getx(){return x;}
double gety(){return y;}
};
double distence(CPoint p,CPoint q)
{
return sqrt((p.getx()-q.getx())*(p.getx()-q.getx())+(p.gety()-q.gety())*(p.gety()-q.gety()));
}
int main()
{
CPoint t1(10,13),t2(2,8);
cout<<distence(t1,t2)<<endl;
return 0;
}
总结:看见个一般函数,就差点写成不定义类的了。。。。。