#include<iostream>
#include<cmath>
using namespace std;
class point
{
public:
point(float i, float j);
friend void dist(point &p1, point &p2);
void show();
private:
float x;
float y;
};
point::point(float i, float j)
{
x = i;
y = j;
}
void point::show()
{
cout << "(" << x << "," << y << ")" << endl;
}
void dist(point &p1, point &p2)
{
float x1, y1, x2, y2;
x1=p1.x;
y1=p1.y;
x2=p2.x;
y2=p2.y;
int a = abs(x2 - x1);
int b = abs(y2 - y1);
int c = sqrt(a*a + b*b);
cout << "两个点之间的距离是" << sqrt(a*a + b*b) << endl;
}
int main()
{
float x1, y1, x2, y2;
cout << "请输入第一个点的坐标: " << endl;
cin >> x1 >> y1;
cout << "请输入第二个点的坐标: " << endl;
cin >> x2 >> y2;
point p1(x1, y1);
p1.show();
point p2(x2, y2);
p2.show();
dist(p1,p2);
return 0;
}
C++作业4.22
最新推荐文章于 2024-03-01 11:19:20 发布