### Problem on using file data in the main ! Thanks

Hello,

I really need your help , so I have a project where I have two classes Personne and Patient, and where patient inherits from personne, also I have a file that contains two columns (Latitude , longitudes) of doctors, what I need is to calculate distance betweek each patient and each doctor in the file

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778`` `````` /*------ Patient function that fill a vector with random Latitude and longitude----*/ void Patient:: fillPatient(vector & NewPatient) { int etat =0; double LatPa; double LongPa; double min1 = 45.173886; double max1 = 45.213861; double min = 0.673541; double max = 0.747362; //unsigned int size = NewPatient.size(); for (unsigned int i =0; i<100; i++){ LatPa = min1 + ((max1 - min1) * (rand () / (double) RAND_MAX)); LongPa = min + ((max - min) * (rand () / (double) RAND_MAX)); etat ++; Patient NewPat(etat,LatPa, LongPa); NewPatient.push_back(NewPat); } } /*-------- function calculate distance ------*/ double Personne::distance( double latA, double longA, double latB, double longB ) // latitude and longitude of arbitrary entities { constexpr double degToRad = 3.14159265358979 / 180.0; // conversion factor, evaluated at compile time const double radEarth = 6371; // mean radius of the earth in km latA *= degToRad; // convert to radians (if originally in degrees) longA *= degToRad; latB *= degToRad; longB *= degToRad; double cosAngle = sin( latA ) * sin( latB ) + cos( latA ) * cos( latB ) * cos( longA - longB ); // cosine of angle between position vectors, from spherical coordinates and dot product return radEarth * acos( cosAngle ); // great-circle distance ( "r x theta" ) } /*------main function -------*/ int main() { ifstream myfile ("C:/Program Files/text.csv");//file that contains latitude and longitude of doctors and it has 2 columns and 379 lignes int lineNumber = 0; int lineNumberSought = 400; // you may get it as argument /*------ Reation d'un vecteur d'objets Patients------*/ vector myPat; Patient::fillPatient(myPat); if (myfile.is_open()) { while (getline(myfile,line)) { istringstream myline(line); while(getline(myline, csvItem, ';')) { //cout << csvItem << endl; for ( k = 0; k < 2; k++ ){ // for (int j =0;j<4; j++){ for( j =0; j <379 ; j++ ){ distanc[j][i] = atof(csvItem.c_str()); double dist = Personne::distance(myPat[k].GetLat(), myPat[k].GetLong(), distanc[j][0] ,distanc[j][1] ); cout << "The distance between patient" << k + 1 << " and doctor " << j + 1 << " is " << dist << "km " << endl; } // k++; } myfile.close(); }}}}//} else { cout << "pas de fichier"<
Last edited on
Topic archived. No new replies allowed.