要求:
原始文件:
结果:
以(0,0)为原点,逆时针旋转30度28分6秒(具体数值忘了,但代码是可输入所需要的度分秒)
具体代码如下:
#include<iostream>
//保留五位小数
#include<iomanip>
#include "stdlib.h"
#include<string>
#include<fstream>
#include<cmath>
#define PI 3.1415926
using namespace std;
int main()
{
ifstream File_Input;
ofstream File_Output("国泰厂地形测量数据修正版.txt");//输出坐标保存在output.txt文件
File_Input.open("国泰厂地形测量数据.txt", ios::in);
string abandon_A;
string abandon_B;
long double X;
long double x1, y1;//输入的坐标
long double x2, y2;//输出的坐标
int a,b,c;
long double n;
cout << "请输入角度(度、分、秒):";
cin >> a >> b >> c;
n = a + b / 60.0 + c / 3600.0;
for (int i = 0; i <155; i++)
{
File_Input >> abandon_A;//第一个(08TP)读到临时变量中
File_Output << abandon_A<<" ";
File_Input >> X >> y1;//输入第二个数字和第三个数字
//如果大于一千万,那就是后四位(一万取余),如果小于一千万大于一百万,那就是后三位(1000取余),小于一百万的都是后四位
if (X < 10000000 && X>1000000)
{
x1 = (int)X % 1000 + (X - (int)X);//double类型不可取余数
}
else
{
x1 = (int)X % 10000 + (X - (int)X);//double类型不可取余数
}
//对第一个和第二个数字进行处理并输出
long double d = sqrt(x1 * x1 + y1 * y1); //该点至原点的距离
long double m = atan2(y1, x1); //m的弧度
x2 = d * cos(n + m);
y2 = d * sin(n + m);
if (i < 2)
File_Output << "000" << i + 1 << setiosflags(ios::fixed) << setprecision(5) << x2 << " " << setiosflags(ios::fixed) << setprecision(5) << y2 << " ";
else if (i >= 2 && i <= 59)
File_Output << 1000 + i - 2 << setiosflags(ios::fixed) << setprecision(5) << x2 << " " << setiosflags(ios::fixed) << setprecision(5) << y2 << " ";
else if (i >= 60 && i <= 102)
File_Output << 1000 + i - 1 << setiosflags(ios::fixed) << setprecision(5) << x2 << " " << setiosflags(ios::fixed) << setprecision(5) << y2 << " ";
else if (i == 103)
File_Output << "0011" << setiosflags(ios::fixed) << setprecision(5) << x2 << " " << setiosflags(ios::fixed) << setprecision(5) << y2 << " ";
else if (i >= 104 && i <= 106)
File_Output << 1000 + i + 2 << setiosflags(ios::fixed) << setprecision(5) << x2 << " " << setiosflags(ios::fixed) << setprecision(5) << y2 << " ";
else
File_Output << 1000 + i + 3 << setiosflags(ios::fixed) << setprecision(5) << x2 << " " << setiosflags(ios::fixed) << setprecision(5) << y2 << " ";
//用getline把后面整行读到临时变量里面
getline(File_Input,abandon_B);
File_Output << abandon_B<<endl;
}
//把最后两行文字输出
getline(File_Input, abandon_B);
File_Output << abandon_B << endl;
getline(File_Input, abandon_B);
File_Output << abandon_B << endl;
cout << "坐标已全部输入至国泰厂地形测量数据修正版.txt文件中" << endl;
File_Input.close();
File_Output.close();
return 0;
}
(帮同济同学代做的,有什么疑问或者其他要求可以再和我交流。)