描述 定义一个Point类,用来描述平面上的一个点,并定义成员函数Move ,支持点的移动操作。 要求:定义三个点A,B,C, 输入 输入三个点的坐标;输入第三个点移动到的目标位置 说明:坐标点的类型为int 输出 输出三个点的坐标。并输出A,B两点之间的距离。 样例输入 0 0 10 0 10 10 20 20 样例输出 (0,0) (10,0) (20,20) 10
时间: 2023-04-05 14:00:41 浏览: 31
定义一个Point类,用来描述平面上的一个点,并定义成员函数Move,支持点的移动操作。
class Point {
public:
int x, y;
Point(int a, int b) : x(a), y(b) {}
void Move(int a, int b) {
x += a;
y += b;
}
};
要求:定义三个点A,B,C,输入三个点的坐标;输入第三个点移动到的目标位置
int main() {
int x1, y1, x2, y2, x3, y3, tx, ty;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> tx >> ty;
Point A(x1, y1), B(x2, y2), C(x3, y3);
C.Move(tx - x3, ty - y3);
说明:坐标点的类型为int
输出三个点的坐标。并输出A,B两点之间的距离。
cout << "(" << A.x << "," << A.y << ") ";
cout << "(" << B.x << "," << B.y << ") ";
cout << "(" << C.x << "," << C.y << ")" << endl;
double distance = sqrt(pow(B.x - A.x, 2) + pow(B.y - A.y, 2));
cout << distance << endl;
样例输入
0 0 10 0 10 10 20 20
样例输出
(0,0) (10,0) (20,20)
10
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)