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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  /*------ Patient function that fill a vector with random Latitude and longitude----*/
void Patient:: fillPatient(vector <Patient>&  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 <Patient> 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"<<endl;
	}
Last edited on
Topic archived. No new replies allowed.