#include
#include
#include
#include
using namespace std;
void Data_Calculate();//数据解算
void Data_Show();//结果打印到屏幕
void Data_Output();//结果输出到TXT
int v[4], i=0;
double h[4], L[4], h_v[4], H[5], f_h;
double sum_h, sum_L, sum_v, sum_Pvv;
void Data_Calculate()
{
H[1] = 47.231; H[4] = 41.918;
h[1] = 7.231; h[2] = -4.326; h[3] = -8.251;
L[1] = 4.5; L[2] = 7.2; L[3] = 7.0;
sum_h = 0; sum_v = 0;
sum_L = L[1] + L[2] + L[3];
for ( i = 1; i < 4; i++ )
sum_h += h[i];
f_h = (sum_h + H[1] - H[4]) * 1000;
for ( i = 1; i < 4; i++ )
v[i] = int((-f_h * L[i] / sum_L)+0.5);//计算高差改正数v
for ( i = 1; i < 4; i++ )
sum_v += v[i];//高差改正数求和
for ( i = 1; i < 4; i++ )
h_v[i] = 0.001 * v[i] + h[i];//改正后高差
for ( i = 2; i < 4; i++ )
H[i] = (H[i-1] + h_v[i-1]);//计算最或然高程
}
void Data_Show()
{
cout << setiosflags(ios::fixed);
cout << "______________________________________________________________" << endl;
cout << "点号" << setw(8) << "距离/km" << setw(12) << "观测高差/m" << setw(15)
<< "高差改正数/mm" << setw(14) << "改正后高差/m" << setw(8) << "高程/m" << endl;
cout << "______________________________________________________________" << endl;
cout << setw(2) << "A" << setw(59) << setprecision(3) << H[1] << endl ;
cout << setw(9) << setprecision(1) << L[1] << setw(12) << setprecision(3) << h[1] << setw(11) << v[1] << setw(17) << h_v[1] << endl;
cout << setw(2) << "1" << setw(59) << setprecision(3) << H[2] << endl;
cout << setw(9) << setprecision(1) << L[2] << setw(12) << setprecision(3) << h[2] << setw(11) << v[2] << setw(17) << h_v[2] << endl;
cout << setw(2) << "2" << setw(59) << setprecision(3) << H[3] << endl;
cout << setw(9) << setprecision(1) << L[3] << setw(12) << setprecision(3) << h[3] << setw(11) << v[3] << setw(17) << h_v[3] << endl;
cout << setw(2) << "B" << setw(59) << setprecision(3) << H[4] << endl;
cout << "______________________________________________________________" << endl;
cout << endl;
}
void Data_Output()
{
ofstream in;
in.open("data.txt",ios::trunc);
in << setw(40) << "附合水准路线解算表" << endl ;
in << "______________________________________________________________" << endl;
in << setiosflags(ios::fixed);
in << "点号" << setw(8) << "距离/km" << setw(12) << "观测高差/m" << setw(15)
<< "高差改正数/mm" << setw(14) << "改正后高差/m" << setw(8) << "高程/m" << endl;
in << "______________________________________________________________" << endl;
in << setw(2) << "A" << setw(59) << setprecision(3) << H[1] << endl ;
in << setw(11) << L[1] << setw(10) << h[1] << setw(11) << v[1] << setw(17) << h_v[1] << endl;
in << setw(2) << "1" << setw(59) << setprecision(3) << H[2] << endl;
in << setw(11) << L[2] << setw(10) << h[2] << setw(11) << v[2] << setw(17) << h_v[2] << endl;
in << setw(2) << "2" << setw(59) << setprecision(3) << H[3] << endl;
in << setw(11) << L[3] << setw(10) << h[3] << setw(11) << v[3] << setw(17) << h_v[3] << endl;
in << setw(2) << "B" << setw(59) << setprecision(3) << H[4] << endl;
in << "______________________________________________________________" << endl;
in.close();
}
int main()
{
cout << endl << setw(40) << "附合水准路线解算表" << endl;
Data_Calculate();
Data_Show();
Data_Output();
cout << "结果输出到根目录data.txt中" << endl << endl;
system("pause");
return 0;
}
主要问题在于输出那边,ofream改成FILE* fp = fopen("data.txt","w+");
后面的输出,改为fprintf("%f",...)
cout直接用printf
你把类class变成结构体
把cout变成printf
把cin变成scanf
把iostream 变成stdio.h
把using namespace std去掉
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。