CDiamond::CDiamond() { } void CDiamond::Set_first_point(CPoint p) { diamond_first_point = p; } void CDiamond::Set_end_point(CPoint p) { diamond_end_point = p; } void CDiamond::Get_other_point(CPoint p) { diamond_1_point.x = diamond_first_point.x; diamond_1_point.y = (diamond_first_point.y + diamond_end_point.y) / 2; diamond_3_point.x = diamond_end_point.x; diamond_3_point.y = diamond_1_point.y; diamond_2_point.y = diamond_first_point.y; diamond_2_point.x = (diamond_first_point.x + diamond_end_point.x) / 2; diamond_4_point.y = diamond_end_point.y; diamond_3_point.x = diamond_2_point.x; } POINT points[] = { { diamond_1_point.x,diamond_1_point.y}, {diamond_2_point.x,diamond_2_point.y}, {diamond_3_point.x,diamond_3_point.y}, {diamond_4_point.x,diamond_4_point.y} };修正这段代码
时间: 2024-03-14 16:42:57 浏览: 126
在这段代码中,`diamond_1_point`、`diamond_2_point`、`diamond_3_point` 和 `diamond_4_point` 都是 `CPoint` 类型的变量,表示钻石形状的四个顶点,且 `diamond_first_point` 和 `diamond_end_point` 也是 `CPoint` 类型的变量,表示图形的起点和终点。
如果要将这四个顶点存储到 `POINT` 类型的数组中,需要在计算出 `diamond_1_point`、`diamond_2_point`、`diamond_3_point` 和 `diamond_4_point` 的值之后,再将其存储到数组中。因此,你需要将 `POINT points[]` 的定义放到 `Get_other_point` 函数中,代码应该如下所示:
```C++
void CDiamond::Get_other_point(CPoint p)
{
diamond_1_point.x = diamond_first_point.x;
diamond_1_point.y = (diamond_first_point.y + diamond_end_point.y) / 2;
diamond_3_point.x = diamond_end_point.x;
diamond_3_point.y = diamond_1_point.y;
diamond_2_point.y = diamond_first_point.y;
diamond_2_point.x = (diamond_first_point.x + diamond_end_point.x) / 2;
diamond_4_point.y = diamond_end_point.y;
diamond_4_point.x = diamond_2_point.x;
POINT points[] = {
{ diamond_1_point.x, diamond_1_point.y },
{ diamond_2_point.x, diamond_2_point.y },
{ diamond_3_point.x, diamond_3_point.y },
{ diamond_4_point.x, diamond_4_point.y }
};
}
```
这里将 `POINT points[]` 的定义移到了 `Get_other_point` 函数中,并且在计算 `diamond_1_point`、`diamond_2_point`、`diamond_3_point` 和 `diamond_4_point` 的值之后,直接将它们存储到了数组中。
阅读全文