问一联创笔试题目,该如何处理
问一联创笔试题目
写一个程序,设计一个点类Point,求两个点之间的距离?
我是就想直接议和函数里面四个参数(代表两个点),总觉得有更好的办法
各位能帮忙帮我写个啊
------解决方案--------------------
你用两个数字表示“点”,还叫啥“类”?点类是要求用一个对象来表示点,而不是用两个数字表示。这是C++最基本的类设计问题哦。
------解决方案--------------------
class Point
{
private:
float x;
float y;
};
最简单的点类的写法
------解决方案--------------------
class Point
{
private:
float x;
float y;
public:
point(float a=0.0f,float b=0.0f):x(a,b){};
friend float distance(Point& left, Point& right)
};
最简单的点类的写法
float distance(Point& left, Point& right){
return ((left.x-right.x)^2+(left.y-right.y)^2)^0.5
}
写一个程序,设计一个点类Point,求两个点之间的距离?
我是就想直接议和函数里面四个参数(代表两个点),总觉得有更好的办法
各位能帮忙帮我写个啊
------解决方案--------------------
你用两个数字表示“点”,还叫啥“类”?点类是要求用一个对象来表示点,而不是用两个数字表示。这是C++最基本的类设计问题哦。
------解决方案--------------------
class Point
{
private:
float x;
float y;
};
最简单的点类的写法
------解决方案--------------------
class Point
{
private:
float x;
float y;
public:
point(float a=0.0f,float b=0.0f):x(a,b){};
friend float distance(Point& left, Point& right)
};
最简单的点类的写法
float distance(Point& left, Point& right){
return ((left.x-right.x)^2+(left.y-right.y)^2)^0.5
}