?? infile.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 + -