c++ 不要注释 题目描述 定义一个记录类型,它的每个值表示X-Y坐标上的一个点,X,Y的取值范围是0到100之间的整数。编一程序,顺时针读入一个四边形的各点a,b,c,d的X-Y值,并判断它是否能构成正方形(Zhengfangxing)、矩形(Juxing)或者其它四边形(Qita)。 输入 见上面 输出 见上面 样例 输入 复制 1 1 0 1 0 0 1 0 输出 复制 Zhengfangxing
时间: 2024-04-17 16:26:43 浏览: 107
cocos2d-x实战 c++卷教程及完整源码
```cpp
#include <iostream>
using namespace std;
struct Point {
int x;
int y;
};
bool isSquare(Point a, Point b, Point c, Point d) {
int side1 = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
int side2 = (b.x - c.x) * (b.x - c.x) + (b.y - c.y) * (b.y - c.y);
int side3 = (c.x - d.x) * (c.x - d.x) + (c.y - d.y) * (c.y - d.y);
int side4 = (d.x - a.x) * (d.x - a.x) + (d.y - a.y) * (d.y - a.y);
if (side1 == side2 && side2 == side3 && side3 == side4) {
return true;
}
return false;
}
bool isRectangle(Point a, Point b, Point c, Point d) {
int dotProduct = (b.x - a.x) * (c.x - b.x) + (b.y - a.y) * (c.y - b.y);
if (dotProduct == 0) {
return true;
}
return false;
}
int main() {
Point a, b, c, d;
cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> d.x >> d.y;
if (isSquare(a, b, c, d)) {
cout << "Zhengfangxing" << endl;
} else if (isRectangle(a, b, c, d)) {
cout << "Juxing" << endl;
} else {
cout << "Qita" << endl;
}
return 0;
}
```
请注意,这段代码会读取四个点的X和Y值,并根据这些点的相对位置判断它们能否构成正方形、矩形或其他四边形。输入应按照顺时针顺序提供四个点的坐标。输出将根据判断结果显示"Zhengfangxing"、"Juxing"或"Qita"。
阅读全文