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

Free Pascal Discussion :

Problème de tri (Carnet d'adresse : modification de contact)


Sujet :

Free Pascal

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 30
    Points : 10
    Points
    10
    Par défaut Problème de tri (Carnet d'adresse : modification de contact)
    Bonjour à tous,
    J'ai fait un carnet d'adresse. Le programme tri les contacts par nom et par prénom (s'il y a plusieurs contacts de même nom). Dans celui-ci, il y a une option "Modifier un contact". Mais quand je modifie le nom ou le prénom d'un contact, celui reste à la même place dans le tableau et les contacts ne sont alors plus dans l'ordre alphabétique. Voici le code source de la fonction de modification. J'ai fait uniquement le tri quand le nom est changé car comme ça ne fonctionne pas, ce n'est pas la peine de le faire pour le prénom car je se sera la même chose.

    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
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    Function Menu_changing (Var t: array of personne; qte: Byte):integer;
    Var i, j, choix: byte; info: personne;
    Begin
     choix:=1;
     gotoxy(35,1);
     WriteLn ('____________________');
     gotoxy(33,4);
     WriteLn ('Modification d''un contact');
     gotoxy(35,6);
     WriteLn ('____________________');
     WriteLn; WriteLn;
     If (qte>0) then
        Begin
           i:=0; choix:=1;
           Write ('Nom:         '); ReadLn (info.nom);
           Write ('Prenom:      '); ReadLn (info.prenom);
           WriteLn;
           clrscr;
           While (info.nom+info.prenom<>t[i].nom+t[i].prenom) AND (i<qte) do i:=i+1;
           If (info.nom+info.prenom=t[i].nom+t[i].prenom) AND (i<qte) then
              Begin
                 While (choix<>0) do
                    Begin
                      gotoxy(35,1);
                      WriteLn ('____________________');
                      gotoxy(33,4);
                      WriteLn ('Modification d''un contact');
                      gotoxy(35,6);
                      WriteLn ('____________________');
                      WriteLn; WriteLn;
                      WriteLn('',t[i].nom,' ',t[i].prenom,', rue ',t[i].rue,' ',t[i].numero,', ',t[i].cp,' ',t[i].localite,'');
                      WriteLn;
                      WriteLn (' Modification');
                      WriteLn (' ------------');
                      WriteLn;
                      WriteLn ('  1) Nom');
                      WriteLn ('  2) Prenom');
                      WriteLn ('  3) Rue');
                      WriteLn ('  4) Numero');
                      WriteLn ('  5) Code postal');
                      WriteLn ('  6) Localite');
                      WriteLn ('  0) Retour');
                      WriteLn;
                      Write ('Que voulez vous faire? '); ReadLn (choix);
                      clrscr;
                      gotoxy(35,1);
                      WriteLn ('____________________');
                      gotoxy(33,4);
                      WriteLn ('Modification d''un contact');
                      gotoxy(35,6);
                      WriteLn ('____________________');
                      WriteLn; WriteLn;
                      Case choix of
                        1: Begin
                              Write ('Nom:    '); ReadLn (info.nom);
                              i:=0;
                              While (info.nom>t[i].nom) AND (i<qte) do i:=i+1;
                              j:=qte;
                              While (j>i) do
                                 Begin
                                    t[j]:=t[j-1];
                                    j:=j-1;
                                 End;
                              t[i].nom:=info.nom;
                           End;
                        2: Begin
                              Write ('Prenom:  '); ReadLn (info.prenom);
                              t[i].prenom:=info.prenom;
                           End;
                        3: Begin
                              Write ('Rue:  '); ReadLn (info.rue);
                              t[i].rue:=info.rue;
                           End;
                        4: Begin
                              Write ('Numero:  '); ReadLn (info.numero);
                              t[i].numero:=info.numero;
                           End;
                        5: Begin
                              Write ('Code postal:  '); ReadLn (info.cp);
                              t[i].cp:=info.cp;
                           End;
                        6: Begin
                              Write ('Localite:  '); ReadLn (info.localite);
                              t[i].localite:=info.localite;
                           End;
                        Else If (choix<>0) then
                           Begin
                              clrscr;
                              gotoxy(35,1);
                              WriteLn ('____________________');
                              gotoxy(42,4);
                              WriteLn ('Erreur  ');
                              gotoxy(35,6);
                              WriteLn ('____________________');
                              WriteLn; WriteLn;
                              WriteLn ('Entrez un numero valide');
                              WriteLn;
                              WriteLn ('Pressez ENTER pour revenir au menu'); ReadLn;
                              clrscr;
                           End;
                        End;
                    End;
              End
           Else
              Begin
                 gotoxy(35,1);
                 WriteLn ('____________________');
                 gotoxy(33,4);
                 WriteLn ('Modification d''un contact');
                 gotoxy(35,6);
                 WriteLn ('____________________');
                 WriteLn; WriteLn;
                 WriteLn ('Ce contact n''existe pas');
                 WriteLn;
                 WriteLn ('Pressez ENTER pour revenir au menu principal'); ReadLn;
                 clrscr;
              End;
        End
     Else
        Begin
           WriteLn ('La liste de contact est vide');
           WriteLn;
           WriteLn ('Pressez ENTER pour revenir au menu principal'); ReadLn;
           clrscr;
        End;
    End;
    Merci d'avance pour votre aide.

  2. #2
    Responsable Pascal, Lazarus et Assembleur


    Avatar de Alcatîz
    Homme Profil pro
    Ressources humaines
    Inscrit en
    Mars 2003
    Messages
    7 939
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ressources humaines
    Secteur : Service public

    Informations forums :
    Inscription : Mars 2003
    Messages : 7 939
    Points : 59 409
    Points
    59 409
    Billets dans le blog
    2
    Par défaut
    Bonjour,

    En quoi consiste ta routine de tri du tableau ? S'agit-il d'une routine qui insère un nouvel élément au bon endroit ou bien d'une routine qui trie le tableau complet ?

    Si c'est la deuxième solution, rien ne t'empêche de l'appliquer systématiquement après toute modification. Mais si c'est la première solution, je pense que tu devras écrire une routine qui trie tout le tableau, à moins d'une solution très moche qui consisterait en la suppression de l'élément modifié pour le réinsérer dans le tableau à l'aide de la routine existante.

    Je suis fatigué, je ne sais pas si ce que j'ai écrit est compréhensible.
    Règles du forum
    Cours et tutoriels Pascal, Delphi, Lazarus et Assembleur
    Avant de poser une question, consultez les FAQ Pascal, Delphi, Lazarus et Assembleur
    Mes tutoriels et sources Pascal

    Le problème en ce bas monde est que les imbéciles sont sûrs d'eux et fiers comme des coqs de basse cour, alors que les gens intelligents sont emplis de doute. [Bertrand Russell]
    La tolérance atteindra un tel niveau que les personnes intelligentes seront interdites de toute réflexion afin de ne pas offenser les imbéciles. [Fiodor Mikhaïlovitch Dostoïevski]

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 30
    Points : 10
    Points
    10
    Par défaut
    Enfaite le tableau est trié par insertion. Donc il compare le nouveau contact avec le premier, si celui-ci est plus grand il le compare avec le contact suivant. Ensuite une fois que le contact est plus petit que celui dans la tableau, on prend le dernier élément du tableau et on le descend de 1 jusqu'à ce qu'on arrive au nouveau contact qui est alors ajouté.

    Pour ce qui est de la suppression de l'élément modifié pour la réinsertion dans le tableau à l'aide de la routine existante. Je ne veux pas. Je veux du beau code.

    Donc oui je voudrais appliquer le tri après chaque modification. Du moins au nom et au prénom vu que les contacts sont trié uniquement par nom et par prénom.


    Voici ce que j'ai fait pour l'instant, ce qui est censé retiré après modification du nom. Mais ça ne fonctionne pas... Ce code est déjà plus haut mais je mets ici que la partie qui fait le tri.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
                      Case choix of
                        1: Begin
                              Write ('Nom:    '); ReadLn (info.nom);
                              i:=0;
                              While (info.nom>t[i].nom) AND (i<qte) do i:=i+1;
                              j:=qte;
                              While (j>i) do
                                 Begin
                                    t[j]:=t[j-1];
                                    j:=j-1;
                                 End;
                              t[i].nom:=info.nom;
                           End;

  4. #4
    Expert confirmé

    Inscrit en
    Août 2006
    Messages
    3 942
    Détails du profil
    Informations forums :
    Inscription : Août 2006
    Messages : 3 942
    Points : 5 654
    Points
    5 654
    Par défaut
    Nea,

    La première chose à faire est d'éclater tout ça en procédures/fonctions pour structurer le programme, et le rendre plus lisible.
    Si les cons volaient, il ferait nuit à midi.

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 30
    Points : 10
    Points
    10
    Par défaut
    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
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    (*-----------------------------------------------MODIFICATION D'UN CONTACT---------------------------------------------*)
     
                                                                             (*Nom*)
    Function Menu_changing_1(Var t: array of personne; Var qte: Byte):integer;
    Var i,j: byte; info: personne;
    Begin
     Write (' Nom:    '); ReadLn (info.nom);
     i:=0;
     While (info.nom+info.prenom>t[i].nom+t[i].prenom) AND (i<qte) do i:=i+1;
     j:=qte;
     While (j>i) do
        Begin
           t[j]:=t[j-1];
           j:=j-1;
        End;
     t[i].nom:=info.nom;
    End;
     
                                                                          (*Prénom*)
    Function Menu_changing_2(Var t: array of personne; Var qte: Byte):integer;
    Var i,j: byte; info: personne;
    Begin
     Write (' Prenom:  '); ReadLn (info.prenom);
     i:=0;
     While (info.nom+info.prenom>t[i].nom+t[i].prenom) AND (i<qte) do i:=i+1;
     j:=qte;
     While (j>i) do
        Begin
           t[j]:=t[j-1];
           j:=j-1;
        End;
     t[i].prenom:=info.prenom;
    End;
     
                                                                             (*rue*)
    Function Menu_changing_3(Var t: array of personne; Var qte: Byte):integer;
    Var i,j: byte; info: personne;
    Begin
     Write (' Rue:  '); ReadLn (info.rue);
     t[i].rue:=info.rue;
    End;
     
                                                                          (*numero*)
    Function Menu_changing_4(Var t: array of personne; Var qte: Byte):integer;
    Var i,j: byte; info: personne;
    Begin
     Write (' Numero: '); ReadLn (info.numero);
     t[i].numero:=info.numero;
    End;
     
                                                                     (*code postal*)
    Function Menu_changing_5(Var t: array of personne; Var qte: Byte):integer;
    Var i,j: byte; info: personne;
    Begin
     Write (' Code postal:  '); ReadLn (info.cp);
     t[i].cp:=info.cp;
    End;
     
                                                                        (*localité*)
    Function Menu_changing_6(Var t: array of personne; Var qte: Byte):integer;
    Var i,j: byte; info: personne;
    Begin
     Write (' Localite:  '); ReadLn (info.localite);
     t[i].localite:=info.localite;
    End;
     
                                                               (*Menu modification*)
    Function Menu_changing (Var t: array of personne; qte: Byte):integer;
    Var i, j, choix: byte; info: personne;
    Begin
     choix:=1;
     gotoxy(35,1); WriteLn ('____________________');
     gotoxy(33,4); WriteLn ('Modification d''un contact');
     gotoxy(35,6); WriteLn ('____________________');
     WriteLn; WriteLn;
     If (qte>0) then
        Begin
           i:=0; choix:=1;
           Write (' Nom:         '); ReadLn (info.nom);
           Write (' Prenom:      '); ReadLn (info.prenom);
           WriteLn;
           clrscr;
           While (info.nom+info.prenom<>t[i].nom+t[i].prenom) AND (i<qte) do i:=i+1;
           If (info.nom+info.prenom=t[i].nom+t[i].prenom) AND (i<qte) then
              Begin
                 While (choix<>0) do
                    Begin
                      gotoxy(35,1); WriteLn ('____________________');
                      gotoxy(33,4); WriteLn ('Modification d''un contact');
                      gotoxy(35,6); WriteLn ('____________________');
                      WriteLn; WriteLn;
                      WriteLn(' ',t[i].nom,' ',t[i].prenom,', rue ',t[i].rue,' ',t[i].numero,', ',t[i].cp,' ',t[i].localite,'');
                      WriteLn;
                      WriteLn (' Modification');
                      WriteLn (' ------------');
                      WriteLn;
                      WriteLn ('  1) Nom');
                      WriteLn ('  2) Prenom');
                      WriteLn ('  3) Rue');
                      WriteLn ('  4) Numero');
                      WriteLn ('  5) Code postal');
                      WriteLn ('  6) Localite');
                      WriteLn ('  0) Retour');
                      WriteLn;
                      Write (' Que voulez vous faire? '); ReadLn (choix);
                      clrscr;
                      gotoxy(35,1); WriteLn ('____________________');
                      gotoxy(33,4); WriteLn ('Modification d''un contact');
                      gotoxy(35,6); WriteLn ('____________________');
                      WriteLn; WriteLn;
                      Case choix of
                        1: Menu_changing_1(t,qte);
                        2: Menu_changing_2(t,qte);
                        3: Menu_changing_3(t,qte);
                        4: Menu_changing_4(t,qte);
                        5: Menu_changing_5(t,qte);
                        6: Menu_changing_6(t,qte);
                        Else If (choix<>0) then
                           Begin
                              clrscr;
                              gotoxy(35,1); WriteLn ('____________________');
                              gotoxy(42,4); WriteLn ('Erreur  ');
                              gotoxy(35,6); WriteLn ('____________________');
                              WriteLn; WriteLn;
                              WriteLn (' Entrez un numero valide');
                              WriteLn;
                              WriteLn (' Pressez ENTER pour revenir au menu'); ReadLn;
                              clrscr;
                           End;
                        End;
                    End;
              End
           Else
              Begin
                 gotoxy(35,1); WriteLn ('____________________');
                 gotoxy(33,4); WriteLn ('Modification d''un contact');
                 gotoxy(35,6); WriteLn ('____________________');
                 WriteLn; WriteLn;
                 WriteLn (' Ce contact n''existe pas');
                 WriteLn;
                 WriteLn (' Pressez ENTER pour revenir au menu principal'); ReadLn;
                 clrscr;
              End;
        End
     Else
        Begin
           WriteLn (' La liste de contact est vide');
           WriteLn;
           WriteLn (' Pressez ENTER pour revenir au menu principal'); ReadLn;
           clrscr;
        End;
    End;

    maintenant que j'ai tout mis dans des fonctions, les changement ne s'effectue même plus. Donc en plus de ne pas le mettre dans l'ordre alphabétique, les modifications ne s'effectue plus.

Discussions similaires

  1. Problème avec le carnet adresses outlook 2007
    Par Michel IDA dans le forum Outlook
    Réponses: 1
    Dernier message: 04/12/2011, 18h56
  2. [Outlook 2003] problème carnet d'adresses
    Par Ksual dans le forum Outlook
    Réponses: 0
    Dernier message: 07/05/2008, 01h28
  3. Problème avec les contacts et le carnet d'adresse
    Par ricain59 dans le forum Outlook
    Réponses: 11
    Dernier message: 13/11/2007, 20h44
  4. problème de tri et optimisatiopn
    Par psyco2604 dans le forum XSL/XSLT/XPATH
    Réponses: 9
    Dernier message: 13/05/2004, 10h44

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