# C++如何转C语言，跪求帮忙转一下，在线等答案-问答-阿里云开发者社区-阿里云

## C++如何转C语言，跪求帮忙转一下，在线等答案

``````#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;
}``````

a123456678 2016-03-05 14:19:08 2195 0
2 条回答

• 主要问题在于输出那边，ofream改成FILE* fp = fopen("data.txt","w+");
后面的输出，改为fprintf("%f",...)
cout直接用printf

2019-07-17 18:53:26
赞同 展开评论 打赏
• 你把类class变成结构体
把cout变成printf
把cin变成scanf
把iostream 变成stdio.h
把using namespace std去掉

2019-07-17 18:53:26
赞同 展开评论 打赏

170
1
0
3078
1
0
3205
2
0
1477
4
0
1418
3
0
2332
1
0
2196
1
0
2623
2
0
1383
1
0
3224
1
0