|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
#include<math.h>
using namespace std;
class point;
class distance
{
private:
double length;
public:
distance(double h);
void qiuhe(point a,point b);
};
class point
{
private:
double x;
double y;
public:
friend class distance;
point(double a,double b);
};
int main()
{
point x1(0,0),x2(0,0);
distance s(1.0);
s.qiuhe(x1,x2);
return 0;
}
point::point(double a,double b)
{
cin>>a>>b;
x=a;y=b;
}
distance::distance(double h)
{
length=h;
cin>>h;
length=h;
}
void distance::qiuhe(point a,point b)
{
distance temp(0.0);
temp=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
cout<<temp.length;
}
using namespace std;
偷懒可不是什么好事
碰巧std命名空间也有一个叫distance这玩意的
- #include<iostream>
- #include<math.h>
- //using namespace std;
- class point;
- class distance
- {
- private:
- double length;
- public:
- distance(double h);
- void qiuhe(point a, point b);
- };
- class point
- {
- private:
- double x;
- double y;
- public:
- friend class distance;
- point(double a, double b);
- };
- int main()
- {
- point x1(0, 0), x2(0, 0);
- distance s(1.0);
- s.qiuhe(x1, x2);
- return 0;
- }
- point::point(double a, double b)
- {
- std::cin >> a >> b;
- x = a; y = b;
- }
- distance::distance(double h)
- {
- length = h;
- std::cin >> h;
- length = h;
- }
- void distance::qiuhe(point a, point b)
- {
- distance temp(0.0);
- temp = sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
- std::cout << temp.length;
- }
复制代码
|
-
|