IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

appel de la fonction du coefficient de DICE ne s’exécute pas correctement


Sujet :

C++

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2020
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Bâtiment

    Informations forums :
    Inscription : Juin 2020
    Messages : 12
    Points : 15
    Points
    15
    Par défaut appel de la fonction du coefficient de DICE ne s’exécute pas correctement
    Bonsoir;
    j'ai un fichier csv de type string, il contient pluieurs lignes et une seul colonne, chaque case contient un nom,
    je veux calculer le coefficient de dice sur ce fichier, la lecture du fichier marche bien, j'ai meme fait des test pour vérifier si la lecture est correcte, mais en utilisant la fonction de dice, le résultat n'est pas correct, en faisant des test d'affichage sur les variables array[i][0], le résultat est vide

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    #include <cstdlib>
    #include <iostream>
    #include<set>
    #include <fstream>
    #include <sstream>
    #include <vector>
    using namespace std;
    vector<vector<string> > array_read(istream &filename);
    static double DiceMatch(string string1, string string2);
    string array[30][30];
    float result;
     
    /************* lire le fichier **********************************************************/
    vector<vector<string> > array_read(istream &filename)
    {
     
        vector< std::vector<string> > array;
        std::vector<string> array_line;
     
        std::string csv_line, word;
        string value;
     
        while ( getline(filename, csv_line) ) {
            array_line.clear();
            std::stringstream ss(csv_line);
     
            //std::cout << "line: " << csv_line << std::endl;
     
            while ( getline(ss, word, ';') ) {
                //value = strtod(word.c_str(), NULL);
                //std::cout << "*) value: " << value << std::endl;
     
                array_line.push_back(word);
                cout<<word<<endl;
            }
     
            array.push_back(array_line);
        }
        return array;
    }
     
    /***************************   DICE  ************************************************/
    //static double DiceMatch(string string1, string string2)
     
    static double DiceMatch(istream &filename)
     
    {
    for(int i=0;i<2;++i)
    for(int j=i+1;j<2;++j)
    {cout<<"1="<<array[i][0]<<endl;
     
    	if (array[i][0].empty() || array[j][1].empty())
           {cout<<"1="<<array[i][0]<<endl;
    		return 0;
        }
     
    	if (array[i][0] == array[j][1])
    	{cout<<"1="<<array[i][0]<<endl;
    		return 1;
    }
    	size_t strlen1 = array[i][0].size();
    	size_t strlen2 = array[j][1].size();
     
    	if (strlen1 < 2 || strlen2 < 2)
    		return 0;
     
    	size_t length1 = strlen1 - 1;
    	size_t length2 = strlen2 - 1;
     
    	double matches = 0;
    	int i = 0;
    	int j = 0;
     
    	while (i < length1 && j < length2)
    	{
    		string a = array[i][0].substr(i, 2);
    		string b = array[j][1].substr(j, 2);
    		int cmp = a.compare(b);
     
    		if (cmp == 0)
    			matches += 2;
     
    		++i;
    		++j;
    	}
     
    	return matches / (length1 + length2);
    }
    }
    /**********************  MAIN*****************************************************************/
    int main(int argc, char *argv[])
    {
        ifstream filename("chaine.csv");
        if (!filename) {
            std::cerr << "main - error: can't open file " << filename << std::endl;
     
            return EXIT_FAILURE;
        }
     
    vector<vector<string> > array=array_read( filename);
     
      for (int i=0;i<2;++i)
      {
          //for (int j=i+1;j<2;++j)
          {
            cout<<"d="<<array[i][0]<<endl;
            }
          } 
          double result = DiceMatch(filename);
          //cout<<result<<endl;
     
        system("PAUSE");
        return EXIT_SUCCESS;
    }

  2. #2
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2020
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Bâtiment

    Informations forums :
    Inscription : Juin 2020
    Messages : 12
    Points : 15
    Points
    15
    Par défaut ,
    Bonjour;
    j'ai modifier le code:
    - supprimer la déclaration de la variable array[30][30] globale,
    - double DiceMatch(vector<vector<string> >array)
    - double result = DiceMatch(array); //l'appel de la fonction DiceMatch

    le programme s'execute et il m'affiche correctement le contenu de la variable array, mais il m'affiche pas la valeur de la variable result,
    j'ai besoin d'une orientation, merci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    #include <cstdlib>
    #include <iostream>
    #include<set>
    #include <fstream>
    #include <sstream>
    #include <vector>
    using namespace std;
    vector<vector<string> > array_read(istream &filename);
    //static double DiceMatch(vector<vector<string>>array);
    //static double DiceMatch(string string1, string string2);
    //string array[30][30];
    float result;
     
    /************* lire le fichier **********************************************************/
    vector<vector<string> > array_read(istream &filename)
    {
     
        vector< std::vector<string> > array;
        std::vector<string> array_line;
     
        std::string csv_line, word;
        string value;
     
        while ( getline(filename, csv_line) ) {
            array_line.clear();
            std::stringstream ss(csv_line);
     
            //std::cout << "line: " << csv_line << std::endl;
     
            while ( getline(ss, word, ';') ) {
                //value = strtod(word.c_str(), NULL);
                //std::cout << "*) value: " << value << std::endl;
     
                array_line.push_back(word);
                cout<<word<<endl;
            }
     
            array.push_back(array_line);
        }
        return array;
    }
     
    /***************************   DICE  ************************************************/
    //static double DiceMatch(string string1, string string2)
     
    //static double DiceMatch(istream &filename)
     double DiceMatch(vector<vector<string> >array)
    {
    for(int i=0;i<2;++i)
    for(int j=i+1;j<2;++j)
    {cout<<"1="<<array[i][0]<<endl;
     
     if (array[i][0].empty() || array[j][1].empty())
           {cout<<"1="<<array[i][0]<<endl;
      return 0;
        }
     
     if (array[i][0] == array[j][1])
     {cout<<"1="<<array[i][0]<<endl;
      return 1;
    }
     size_t strlen1 = array[i][0].size();
     size_t strlen2 = array[j][1].size();
     
     if (strlen1 < 2 || strlen2 < 2)
      return 0;
     
     size_t length1 = strlen1 - 1;
     size_t length2 = strlen2 - 1;
     
     double matches = 0;
     int i = 0;
     int j = 0;
     
     while (i < length1 && j < length2)
     {
      string a = array[i][0].substr(i, 2);
      string b = array[j][1].substr(j, 2);
      int cmp = a.compare(b);
     
      if (cmp == 0)
       matches += 2;
     
      ++i;
      ++j;
     }
     
     return matches / (length1 + length2);
    }
    }
    /**********************  MAIN*****************************************************************/
    int main(int argc, char *argv[])
    {
        ifstream filename("chaine.csv");
        if (!filename) {
            std::cerr << "main - error: can't open file " << filename << std::endl;
     
            return EXIT_FAILURE;
        }
     
    vector<vector<string> > array=array_read( filename);
     
      for (int i=0;i<2;++i)
      {
          //for (int j=i+1;j<2;++j)
          {
            cout<<"d="<<array[i][0]<<endl;
            }
          } 
          //double result = DiceMatch(filename);
          double result = DiceMatch(array);
          cout<<result<<endl;
     
        system("PAUSE");
        return EXIT_SUCCESS;
    }

Discussions similaires

  1. [Signal] coefficient de fourier !!!
    Par bessonnet dans le forum Traitement du signal
    Réponses: 7
    Dernier message: 19/12/2006, 14h37
  2. Réponses: 8
    Dernier message: 03/04/2006, 23h24
  3. [VBA] ACCESS - Coefficient de correlation en SQL
    Par fredkrug dans le forum VBA Access
    Réponses: 8
    Dernier message: 25/01/2006, 08h31
  4. Déterminer les coefficients moyens d'une équation linéaire
    Par Oliveuh dans le forum Algorithmes et structures de données
    Réponses: 8
    Dernier message: 11/01/2005, 23h23
  5. Recherche des coefficients d'une matrice 3x3
    Par colorid dans le forum Algorithmes et structures de données
    Réponses: 6
    Dernier message: 25/11/2004, 16h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo