bonsoir,
pour un travail de fac je doit réaliser 3 arbres lexicographiques a partir de fichier txt.
Le but de ce TP est de remplir un arbre lexicographique avec les mots d'un texte,
compter le nombre d’occurrences de chaque mot afin de dire quel est le mot le plus
fréquent. Vous répondrez aussi à la question quel est le mot le plus long du texte.
Mais j'ai un soucis d'erreur quand je veux compiler mon programme et je n'arrive pas a trouver d'ou peut venir l erreur
voici mon code si quelqu'un peut me renseigner
ABRLEX.H
ABRLEX.cpp
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 #ifndef ABRLEX_H #define ABRLEX_H #include <iostream> using namespace std; class ArbreLex { private : noeud* racine; noeud* current; public : ArbreLex(); ~ArbreLex(); bool find(char name); bool chercher(int x,noeud* buffer,char name); Insertion(string ligne); ajout(noeud*x,noeud*y); }; struct noeud { char s; noeud*fg; noeud*frd; int Occurrences; constructionNoeud(char *s,noeud* y,noeud* z); Supression(noeud* r); }; #endif // ABRLEX_H
Main.cpp
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 #include "ABRLEX.h" #include <iostream> using namespace std; ABRLEX::ABRLEX() { racine=constructionNoeud("/"); current=racine; } ABRLEX::~ABRLEX() { Suppression(noeud * racine) } noeud *ABRLEX::constructionNoeud(char s) { noeud* n=new noeud(s); noeud *y= new noeud(); n->fg=y; } void ABRLEX::Insertion(string ligne, int Occurrences) { current=racine; int a = ligne.length(); int b = a+1; char[] tab = new char[b]; for(int i = 0; i < a;i++) { if (i=b-1) { char c = static_cast<int>(Occurences); tab[i]=c; } else { tab[i] = ligne.charAt(i); if (!find(tab[i])) { if(current->frd!=NULL) { current=current->frd; ajout(constructionNoeud(tab[i]),current); } else current->frd=constructionNoeud(tab[i]); } } } } void ABRLEX::affichage() { if(root !=NULL) { affiche(root); } } void ABRLEX::affiche(noeud*r) { if(r) { affiche(r->fg); cout<<r->info<<endl; if(r->frd != NULL) affiche(r->frd); else cout <<"le nombre d'occurence de ce mot est de : "<< affiche(r->frd)<< endl; } } void ABRLEX::ajout(noeud*x,noeud*y) { current=y; current->fg=x; } bool ABRLEX::find(char name) { noeud*buffer=new noeud(); noeud*buffer=current->fg; return chercher(0,buffer,name); } bool ABRLEX::chercher(int x,noeud* buffer,name) if(buffer!=NULL) { if(strcomp(buffer->info,name)==0) { current=buffer; return true; } chercher(x+1,buffer->fg); chercher(x+1,buffer->frd); } return false; } noeud * ABRLEX::Suppression(noeud *r) { if(r) { Suppression(r->fg); Suppression(r->frd); delete r; } }
au cas où certains voudrais voir les question du TP pour comprendre les différentes fonctions les voici
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 #include <iostream> #include <fstream> #include <string> #include <limits> // pour utiliser numeric_limits<int>::max() #include "ABRLEX.h" using namespace std; int main() { string texte = "texte-petit.txt"; ArbreLex texte ; ifstream fichier_texte(texte.c_str(), ios::in); if(fichier_texte.fail()) cout << "Le fichier " << texte << " n'existe pas !" << endl; ifstream fichier("texte-petit.txt", ios::in); if(!fichier.fail()) { cout << "Le fichier existe bien et est correctement ouvert !" << endl; cout << "Le fichier contient : " << endl << endl; string ligne; while(getline(fichier, ligne)) { int Occurrences = count(istream_iterator<string>(fichier), istream_iterator<string>(), ligne); texte.Insertion(ligne,Occurrences); } fichier.close(); } else cerr << "Impossible d'ouvrir le fichier !" << endl; string texte1= "texte-moyen.txt"; ArbreLex texte1; ifstream fichier1_texte1(texte1.c_str(), ios::in); if(fichier1_texte1.fail()) cout << "Le fichier " << texte1 << " n'existe pas !" << endl; ifstream fichier1("texte-moyen.txt", ios::in); if(!fichier1.fail()) { cout << "Le fichier existe bien et est correctement ouvert !" << endl; cout << "Le fichier contient : " << endl << endl; string ligne1; while(getline(fichier1, ligne1)) { int Occurrences = count(istream_iterator<string>(fichier1), istream_iterator<string>(), ligne1); texte1.Insertion(ligne1,Occurrences); } fichier1.close(); } else cerr << "Impossible d'ouvrir le fichier !" << endl; string texte2 = "texte-gros.txt"; ArbreLex texte2; ifstream fichier2_texte2(texte2.c_str(), ios::in); if(fichier2_texte2.fail()) cout << "Le fichier " << texte2 << " n'existe pas !" << endl; ifstream fichier2("texte-gros.txt", ios::in); if(!fichier2.fail()) { cout << "Le fichier existe bien et est correctement ouvert !" << endl; cout << "Le fichier contient : " << endl << endl; string ligne2; while(getline(fichier2, ligne2)) { int Occurrences = count(istream_iterator<string>(fichier2), istream_iterator<string>(), ligne2); texte2.Insertion(ligne2,Occurence); } fichier2.close(); } else cerr << "Impossible d'ouvrir le fichier !" << endl; return 0; }
et voici les erreurs de compilationQuestion 1
Modifier les structures de manière à associer à chaque mot du lexique un entier, cet
entier sera stocké en fin de mot.
Question 2
Écrire les fonctions nécessaires au remplissage de l'arbre avec les mots du fichier
tout en comptant le nombre de fois que chaque mot est présent. L'algorithme de
comptage est :
pour chaque mot du texte, le chercher dans l'arbre, s'il est déjà présent, incrémenter
son compteur sinon ajouter le mot. Indice : la recherche et l'insertion se font dans la
même opération.
Question 3
Écrire une fonction d'affichage du lexique stocké dans l'arbre avec le nombre
d'occurence de chaque mot.
Question 4
Écrire une fonction qui cherche le mot le plus fréquent dans l'arbre.
Question 5
Écrire une fonction qui cherche le mot le plus long dans l'arbre.
Pour réaliser ce TP 3 textes fournis, un petit, un moyen, un gros.
||=== Build: Debug in tpabrNAIRLEX (compiler: GNU GCC Compiler) ===|
include\ABRLEX.h|10|error: 'noeud' does not name a type|
include\ABRLEX.h|11|error: 'noeud' does not name a type|
include\ABRLEX.h|16|error: 'noeud' has not been declared|
include\ABRLEX.h|18|error: 'noeud' has not been declared|
include\ABRLEX.h|18|error: 'noeud' has not been declared|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp||In function 'int main()'
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|11|error: conflicting declaration 'ArbreLex texte'|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|10|note: previous declaration as 'std::string texte'|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|23|error: 'istream_iterator' was not declared in this scope|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|23|error: expected primary-expression before '>' token|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|23|error: expected primary-expression before '>' token|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|23|error: expected primary-expression before ')' token|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|23|error: 'count' was not declared in this scope|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|24|error: 'std::string' has no member named 'Insertion'|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|32|error: conflicting declaration 'ArbreLex texte1'|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|31|note: previous declaration as 'std::string texte1'|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|44|error: 'istream_iterator' was not declared in this scope|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|44|error: expected primary-expression before '>' token|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|44|error: expected primary-expression before '>' token|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|44|error: expected primary-expression before ')' token|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|44|error: 'count' was not declared in this scope|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|45|error: 'std::string' has no member named 'Insertion'|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|53|error: conflicting declaration 'ArbreLex texte2'|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|52|note: previous declaration as 'std::string texte2'|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|65|error: 'istream_iterator' was not declared in this scope|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|65|error: expected primary-expression before '>' token|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|65|error: expected primary-expression before '>' token|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|65|error: expected primary-expression before ')' token|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|65|error: 'count' was not declared in this scope|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|66|error: 'std::string' has no member named 'Insertion'|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|66|error: 'Occurence' was not declared in this scope|
C:\Users\User\Desktop\tpabrNAIRLEX\main.cpp|65|warning: unused variable 'Occurrences' [-Wunused-variable]|
||=== Build failed: 27 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
Partager