赞
踩
C++测绘程序设计(长安大学编)练习题2第15-26题代码,仅供参考。
#include <iostream>
#include <string>
using namespace std;
int main()
{
int num;
string str;
cout << "请输入一个数值和一个字符串,中间用空格隔开:" << endl;
cin >> num >> str;
cout << "输入的数值为:" << num << endl;
cout << "输入的字符串为:" << str << endl;
return 0;
}
#include<iostream> #include<fstream> using namespace std; int main() { ofstream ou; ou.open("D:\\C++测绘程序设计\\编程作业\\test2\\输出文件流.txt", ios::_Nocreate); //如果没有不自动创建 if (!ou) { cout << "文件打开失败"; exit(1); } ifstream in; in.open("D:\\C++测绘程序设计\\编程作业\\test2\\输入文件流.txt", ios::_Nocreate); if (!in) { cout << "文件打开失败"; exit(1); } int a ; string str; in >> a >> str;//从输入文件流.txt文件中读入a和字符串str in.close(); ou << a << str;//向输出文件流.txt文件中写入a和字符串str ou.close(); cout << "文件读写完成!" << endl; return 0; }
#include<iostream> using namespace std; double PI = 3.14159265; double HD_DFM(double HD) { double DFM; int ddd = int(HD / PI * 180); int ff = int((HD / PI * 180 - ddd) * 60); double mm = (((HD / PI * 180 - ddd) * 60) - ff) * 60; DFM = ddd + ff * 1e-2 + mm * 1e-4; return DFM; } double DFM_HD(double DFM) //其中用实数表示角度制的格式ddd.ffmmm...m { double HD; int ddd = int(DFM); int ff = int((DFM - ddd) * 1e2); double mm = (DFM - ddd - ff / 100) * 3600; HD = (mm / 3600 + ff / 60 + ddd) / 180 * PI; return HD; } int main() { double DFM = 180.3030333; double HD = 3.14; cout << "度分秒" << DFM << "转弧度:" << DFM_HD(DFM) << endl; cout << "弧度" << HD << "转度分秒:" << HD_DFM(HD) << endl; return 0; }
#include <iostream> #include <cmath> double PI = 3.14159265; using namespace std; double Afa(double dx, double dy) { double a = 0; if (dx == 0) // 处理dx等于0的情况 { if (dy > 0) { a = 90; } else if (dy < 0) { a = 270; } else a = 0; } else { a = atan(dy / dx) * 180 / PI;//tan(x)定义域在[-PI/2,PI/2] if (dx < 0) a += 180; else if (dy < 0) a += 360; } return a; } int main() { double dx = 1.0, dy = 1.0; double a = Afa(dx, dy); cout << "坐标方位角为:" << a << "度" << endl; return 0; }
#include <iostream> #include <cmath> double PI = 3.14159265; using namespace std; void CL_ZHS(double D, double a, double& dx, double& dy) { double angle = a * PI / 180.0;//注:大地坐标系xy轴与数学直角坐标轴xy不同 dx = D * cos(angle); dy = D * sin(angle); } int main() { double D = 10.0, a = 30.0;//边长D设为10,坐标方位角a设为30度 double dx = 0, dy = 0; CL_ZHS(D, a, dx, dy); cout << "坐标增量为(" << dx << ", " << dy << ")" << endl; return 0; }
#include <iostream> #include<fstream> #include <cmath> double PI = 3.14159265; using namespace std; int main() { double a = PI / 6; double b = 1.0; double c = -3.1415; double d = 6.66; double e = 2.0; double arr[10]; arr[0] = sin(a);//正弦函数 arr[1] = cos(a);//余弦函数 arr[2] = tan(a);//正切函数 arr[3] = atan(b);//反正切函数 arr[4] = fabs(c);//取绝对值 arr[5] = int(d);//取整函数 arr[6] = sqrt(e);//取平方根函数 arr[7] = asin(1 / sqrt(e));//反正弦函数 arr[8] = acos(1 / sqrt(e));//反正切函数 arr[9] = pow(e, 3);//幂函数 cout << "sin(PI / 6)、cos(PI / 6)、tan(PI / 6)、atan(1.0)、fabs(-3.1415)、int(6.66)、sqrt(2.0)、asin(1 / sqrt(2))、" << "acos(1 / sqrt(2))、pow(2, 3) = " << endl; for (int i = 0; i < 10; i++) { cout << arr[i] << " "; } cout << endl << "计算完毕!" << endl; return 0; }
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { string str1, str2; cout << "请输入字符串1:" << endl; getline(cin, str1); //接收一个字符串,可以接收空格并输出,需包含“#include<string>” cout << "请输入字符串2:" << endl; getline(cin, str2); cout << "字符串1为:" << str1 << endl; cout << "字符串2为:" << str2 << endl; if (str1 == str2) cout << "字符串1和字符串2相等" << endl; else cout << "字符串1和字符串2不相等" << endl; string str3 = str1 + str2; // 字符串连接 cout << "字符串1和字符串2连接后为:" << str3 << endl; ifstream fin("text.txt");//默认路径 if (fin) { string str4; getline(fin, str4); // 从文本文件输入字符串 cout << "从文件中读取的字符串为:" << str4 << endl; } else { cout << "打开文件失败" << endl; } return 0; }
#include <iostream> #include <cmath> const double PI = 3.14159265; using namespace std; double DFM_HD(double DFM) //将度分秒转弧度(使用第17题函数),其中DFM是用实数表示角度制,格式为ddd.ffmmm...m { double HD; int ddd = int(DFM); int ff = int((DFM - ddd) * 1e2); double mm = (DFM - ddd - ff / 100) * 3600; HD = (mm / 3600 + ff / 60 + ddd) / 180 * PI; return HD; } // 单向三角高程 计算高差 double DX_SJGC(double D, double DFM, double instrumentH, double targetH) { double HD = DFM_HD(DFM); // 将竖直角转换为弧度值 double deltaH = D * tan(HD) + targetH - instrumentH; // 计算高差 return deltaH; } int main() { double D = 173; // 两点间水平距离 double DFM = 30.0000; // 竖直角(度度度.分分秒秒) double instrumentH = 1.5; // 仪器高 double targetH = 1.5; // 镜高 double deltaH = DX_SJGC(D, DFM, instrumentH, targetH);//输入数据为两点间的水平距离D、竖直角DFM、仪器高与镜高,计算两点高差。 cout << "两点间高差为:" << deltaH << endl; return 0; }
#include <iostream> #include <cmath> double PI = 3.14159265; using namespace std; double DFM_HD(double DFM) //将度分秒转弧度制(使用第17题函数),其中DFM是用实数表示角度制,格式为ddd.ffmmm...m { double HD; int ddd = int(DFM); int ff = int((DFM - ddd) * 1e2); double mm = (DFM - ddd - ff / 100) * 3600; HD = (mm / 3600 + ff / 60 + ddd) / 180 * PI; return HD; } // 往返三角高程计算 double WF_SJGC(double startH, double D, double frontDFM, double backDFM, double frontInstrumentH, double frontTargetH, double backInstrumentH, double backTargetH) { double HDf = DFM_HD(frontDFM); double HDb = DFM_HD(backDFM); // 计算前后视高差 double deltaHf = D * tan(HDf) + frontTargetH - frontInstrumentH; double deltaHb = D * tan(HDb) + backTargetH - backInstrumentH; // 计算终点高程 double endH = startH + (deltaHf + deltaHb) / 2.0; // 计算限差 double limit = 40.0 * sqrt(D / 1000.0); // 判断是否超限 if (fabs(deltaHf - deltaHb) > limit / 1000) { return -1e8; } return endH; } int main() { double startH = 100.0; // 起点高程 double D = 173.0; // 两点间水平距离 double frontDFM = 30.2830; // 往测竖直角(度度度.分分秒秒) double backDFM = 30.2810; // 反测竖直角 double frontInstrumentH = 1.5; // 往测仪器高 double frontTargetH = 3.0; // 往测镜高 double backInstrumentH = 1.5; // 返测仪器高 double backTargetH = 3.0; // 返测镜高 double endH = WF_SJGC(startH, D, frontDFM, backDFM, frontInstrumentH, frontTargetH, backInstrumentH, backTargetH); if (endH == -1.0e8) { cout << "前后视高差超限!" << endl; } else { cout << "终点高程为:" << endH << endl; } return 0; }
#include <iostream> #include<fstream> #include <cmath> double PI = 3.14159265; using namespace std; double DFM_HD(double DFM) //将度分秒转弧度制(使用第17题函数),其中DFM是用实数表示角度制,格式为ddd.ffmmm...m { double HD; int ddd = int(DFM); int ff = int((DFM - ddd) * 1e2); double mm = (DFM - ddd - ff / 100) * 3600; HD = (mm / 3600 + ff / 60 + ddd) / 180 * PI; return HD; } // 往返三角高程计算 void File_SJGC(double** arr, int n, int& error) { double* startH = new double[n]; //起点高程 double* D = new double[n];//两点间的水平距离D double* HDf = new double[n]; //往测竖直角DFM1 double* HDb = new double[n];//返测竖直角DFM2 double* frontInstrumentH = new double[n]; //往测仪器高 double* frontTargetH = new double[n];//往测镜高 double* backInstrumentH = new double[n];//返测仪器高 double* backTargetH = new double[n];//返测镜高 double* deltaHf = new double[n];//往测高差 double* deltaHb = new double[n];//返测高差 for (int i = 0; i < n; i++) { HDf[i] = DFM_HD(arr[i][2]);//竖直角转换成弧度值 HDb[i] = DFM_HD(arr[i][3]); } for (int i = 0; i < n; i++) { //观测数据赋值 D[i] = arr[i][1]; frontTargetH[i] = arr[i][5]; frontInstrumentH[i] = arr[i][4]; backTargetH[i] = arr[i][7]; backInstrumentH[i] = arr[i][6]; // 计算前后视高差 deltaHf[i] = D[i] * tan(HDf[i]) + frontTargetH[i] - frontInstrumentH[i]; deltaHb[i] = D[i] * tan(HDb[i]) + backTargetH[i] - backInstrumentH[i]; // 计算终点高程 double* endH = new double[n]; startH[i] = arr[i][0]; endH[i] = startH[i] + (deltaHf[i] + deltaHb[i]) / 2.0; // 计算限差 double* limit = new double[n]; limit[i] = 40.0 * sqrt(D[i] / 1000.0); // 判断是否超限 if (fabs(deltaHf[i] - deltaHb[i]) > limit[i] / 1000) { endH[i] = -1e8; } ofstream out; out.open("D:\\C++测绘程序设计\\编程作业\\test2\\往返测三角高程观测数据.txt", ios::_Nocreate | ios::app);//没有不创建,追加写入 if (!out) { cout << "文件打开失败"; exit(1); } else { out << "计算第" << i + 1 << "个终点高程结果为:" << endH[i] << endl; if (endH[i] == -1e8) { out << "前后视高差超限!" << endl; error += 1; } } } } int main() { int n; ifstream in; in.open("D:\\C++测绘程序设计\\编程作业\\test2\\往返测三角高程观测数据.txt", ios::_Nocreate); if (!in) { cout << "文件打开失败1"; exit(1); } else { in >> n; double** arr = new double* [n];//(C语言)先给二维数组的每一行开辟一块空间,用来指向每一行(即存放每一行的地址) for (int i = 0; i < n; i++) { arr[i] = new double[8];//然后分别为每一行再开辟内存,用来管理列 } for (int i = 0; i < n; i++) { for (int j = 0; j < 8; j++) { in >> arr[i][j];//用观测数据给二纬数组赋初值 } } int error = 0; File_SJGC(arr, n, error); string str; in >> str; for (int i = 0; i < n; i++) { delete[] arr[i]; } delete[]arr; cout << "一共" << n << "个对向观测三角高程数据计算写入完成!有" << error << "个前后视高差超限。" << endl << str; in.close(); } return 0; } /*文本文件: 2 100 173 20.2830 30.2810 1.5 3.0 1.5 3.0 100 50 45.2830 45.2810 1.5 3.0 1.5 3.0 数据格式为:2个对向观测三角高程数据。从左到右为:起点高程、两点间的水平距离D、往测竖直角DFM1、往测竖直角DFM2、往测仪器高、镜高、往测仪器高、镜高。 */
后续持续更新中…
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。