⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 infile.cpp

📁 用GPSRTK观测数据时
💻 CPP
字号:
#include "iostream.h"
#include "fstream.h"
#include "iomanip.h"
#include "stdlib.h"
#include "string.h"
#include "math.h"
#define file1 "10-12.txt"
#define file2 "10-12name.txt"
#define result "result10-12.txt"

int getpointname()
{	  
	int i=0;
	char ch[20]={'1',' '},sr[10]={'m','a',' ',' '},string[10]={'m','a',' ',' '};
	double x=0,y=0,h=0;

	ifstream inClientFile(file1,ios::in);
	if(!inClientFile)
	{
		cerr<<"File could not be opened!"<<endl;
		exit(1);   
	}

	ofstream outClientFile(file2,ios::out);
    if(!outClientFile)			
	{// overloaded ! operator
	   cerr<<"File could not be opened!"<<endl;
	   exit(1);   //prototype in stdlib.h
	}		

    while(inClientFile>>ch)
	{  
		//下面以四位来区别点位名称,主要看观测时输入点位的规范,也可以前两位进行区别
		//if(ch[0]!=sr[0]&&ch[1]!=sr[1]&&ch[2]!=sr[2]&&ch[3]!=sr[3])
        if(ch[0]!=sr[0]||ch[1]!=sr[1])
		{
			{
                for(i=0;i<4;i++) string[i]=ch[i];
	        	outClientFile<<' '<<string;
		        outClientFile<<'\n';
			}
                for(i=0;i<4;i++) sr[i]=ch[i];
		}
		inClientFile>>x>>y>>h;	
	}
			
	return 0;//ofstream destructor closes file
}	

void com(char sr[],ofstream outClientFile)
{
	int count=0,n=0,i=0,k=0;
	double x=0,y=0,h=0,X=0,Y=0,H=0,vx=0,vy=0,vh=0;
    char ch[20]={'1',' '},str[10]={'m',' '},sp[3]={' ',' '};
	ifstream inClientFile(file1,ios::in);
	
	if(!inClientFile)
	{
		cerr<<"File could not be opened!"<<endl;
		exit(1);   
	}
	while(inClientFile>>ch)
	{  
		//下面以四位来区别点位名称,主要看观测时输入点位的规范,也可以前两位进行区别
		//if(ch[0]==sr[0]&&ch[1]==sr[1]&&ch[2]==sr[2]&&ch[3]==sr[3])
		if(ch[0]==sr[0]&&ch[1]==sr[1])
		{inClientFile>>x>>y>>h;
		{    
			n++;
			H+=h;X+=x;Y+=y;
		}
		}
	}
	
    H=H/n;X=X/n;Y=Y/n;
    ifstream File(file1,ios::in);
	while(File>>ch)
	{   
		//下面以四位来区别点位名称,主要看观测时输入点位的规范,也可以前两位进行区别
		//if(ch[0]==sr[0]&&ch[1]==sr[1]&&ch[2]==sr[2]&&ch[3]==sr[3])
		if(ch[0]==sr[0]&&ch[1]==sr[1])
		{
			File>>x>>y>>h;
			{   
			vx+=(x-X)*(x-X)/n;
            vy+=(y-Y)*(y-Y)/n;
			vh+=(h-H)*(h-H)/n;
			}
		}
	}

	cout<<"\n Next is the result of point "<<sr;
	cout<<"\n There are "<<n<<"  records,and the average is:"<<endl;
    cout<<"\n X="<<X<<endl;
	cout<<"\n Y="<<Y<<endl;
	cout<<"\n H="<<H<<endl;
	if(n>1)
	{
	cout<<"\n 内符合精度如下:"<<endl;
	cout<<"\n X方向 vx="<<sqrt(vx)<<endl;
	cout<<"\n Y方向 vy="<<sqrt(vy)<<endl;
	cout<<"\n H方向 vh="<<sqrt(vh)<<endl;	
	}
	else cout<<"  坐标名称输入可能不规范!"<<"\n  无法求出该点("<<sr<<")的内符合精度,请核对后重新运行!"<<endl;
	
	//保存为文件,存在result.txt中
	outClientFile<<' '<<sr<<'('<<n<<')'<<'\n';
    outClientFile<<X<<sp<<Y<<sp<<H<<'\n';
    outClientFile<<sqrt(vx)<<sp<<sqrt(vy)<<sp<<sqrt(vh)<<sp<<sqrt(vx+vy)<<'\n';
	outClientFile<<'\n';
}



int main()
{
	cout<<"\n程序将计算出点位坐标平均值及内符合精度!"<<endl;
    char sr[10]={'m',' '};
    //cout<<"\n please input the name of point to deal "<<endl;cin>>sr;
	//ifstream constructor opens file
	//char sh[20]; 
    //cout<<"please input the file name:"<<endl; cin>>sh;
	//ifstream inClientFile(sh,ios::in);

	getpointname();

    ifstream inClientFile(file2,ios::in);
	if(!inClientFile)
	{
		cerr<<"File could not be opened!"<<endl;
		exit(1);   
	}

	ofstream outClientFile(result,ios::out);
    if(!outClientFile)			
	{// overloaded ! operator
	   cerr<<"File could not be opened!"<<endl;
	   exit(1);   //prototype in stdlib.h
	}
	
    while(inClientFile>>sr)
	{
		com(sr,outClientFile);
	}

	return 0;//ifstream destructor closes file
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -