使用c++写一个三角形缩放的程序
时间: 2023-12-05 09:03:18 浏览: 28
好的,以下是一个简单的C++程序,用于对三角形进行缩放:
```c++
#include <iostream>
using namespace std;
struct Point {
double x, y;
};
int main() {
Point A, B, C;
double scale;
cout << "Enter coordinates of triangle A: ";
cin >> A.x >> A.y;
cout << "Enter coordinates of triangle B: ";
cin >> B.x >> B.y;
cout << "Enter coordinates of triangle C: ";
cin >> C.x >> C.y;
cout << "Enter scale factor: ";
cin >> scale;
// Scale the triangle
A.x *= scale;
A.y *= scale;
B.x *= scale;
B.y *= scale;
C.x *= scale;
C.y *= scale;
// Output the scaled triangle
cout << "Scaled triangle: " << endl;
cout << "(" << A.x << "," << A.y << ")" << endl;
cout << "(" << B.x << "," << B.y << ")" << endl;
cout << "(" << C.x << "," << C.y << ")" << endl;
return 0;
}
```
这个程序首先定义了一个 `Point` 结构体,用于存储三角形的三个顶点。然后程序会提示用户输入三角形的三个顶点坐标和缩放因子。接着程序会对三个顶点进行缩放,然后输出缩放后的三角形的三个顶点坐标。
请注意,这个程序没有进行任何错误检查和边界检查,实际应用中需要根据具体情况进行补充。