下のコードの中で入力用、出力用にファイルを開いています。「処理に用いるデータを入力ファイルから読み込み、結果を出力用ファイルに書き出す様にプログラムしなければならない」のですが、以下2つの点が分かりません。
class Vector2Dは別ファイルですがこの質問には多分関係ないので省略します。
•出力用ファイルに書き出すとはどういう意味が分からない
•どのように書き直せばよいのか分からない
解答お願いいたします。
lang
1#include <iostream> 2#include "Vector2D.h" 3#include <cmath> 4#include <fstream> 5#include <vector> 6#include <algorithm> 7using namespace std; 8 9class lesserX{ 10public: 11 bool operator()(const Vector2Df& a,const Vector2Df& b){ 12 return (a.x*a.x)+(a.y*a.y)<(b.x*b.x)+(b.y*b.y); 13 }}; 14 15int main(){ 16 float a,b; 17 int i=0; 18 vector <float> p,q; 19 ifstream fin("points.dat"); 20 ofstream fout("out.dat"); 21 while(cin>>a>>b){ 22 p.push_back(a); 23 q.push_back(b); 24 i++; 25 }; 26 27Vector2D <float> dot[i]; 28for (int j= 0; j < i; j++) 29 { 30 dot[j].set(p[j],q[j]); 31 }; 32 sort(dot,dot+i,lesserX()); 33 34 cout<<"median:"<<dot[i/2].x<<" "<<dot[i/2].y<<endl; 35 for (int t = 0; t < i; t++) 36 { 37 cout<<dot[t].x<<" "<<dot[t].y<<" length:"<<dot[t].length()<<endl; 38 } 39 40 41}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/02/18 05:38