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

Pascal Discussion :

Affichage des enregistrements


Sujet :

Pascal

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Inscrit en
    Mai 2008
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 4
    Par défaut Affichage des enregistrements
    bonjour à tous au fait j'ai un projet à rendre vendredi et j'ai un énorme probléme avec le projet. il sagit d'un enregistrement intitulé 'message' avec 5 variable de expéditeur et destinataire de type presonne,contenu de type srting,piece jointe de type reponse(oui ou non) et date de type dates. mais dans le programme on doit utiliser un tableau de type message pour stocker les informations. donc l'utilisateur entre le nombre de message qu'il veut saisir puis effectue la saisie mais mon probléme se trouve au niveau de l'affichage quand on saisi plus d'un message et qu'on demande d'afficher c'est le dernier message saisi qui saffiche plusieurs fois. AIDEZ MOI SVP voici le code de mon programme
    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
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    program fanta;
    uses crt;
    type personne=record
         nom1,prenom1,nom2,prenom2:string;
    end;
    type dates=record
         jour,mois,annee:integer;
    end;
    type reponse=record
          oui,non:string;
    end;
    type message=record
          expediteur,destinataire:personne;
          contenu:string;
          date:dates;
          piece_jointe:reponse;
    end;
    const n=10;
    var t:array[1..n] of message;
        i,m,choix:integer;
        p:personne;
        pic:reponse;
        d:dates;
        nom1,nom2,prenom1,prenom2,rep,reponse1:string;
     
     
    Procedure menu;
    begin
         repeat
               writeln;
               writeln;
               writeln;
               writeln;
               writeln;
               writeln('':15,'1:POUR LA SAISIE D''UN MESSAGE TAPEZ 1');
               writeln;
               writeln;
               writeln;
               writeln;
               writeln;
               writeln('':15,'2:POUR VOIR LE MESSAGE AU COMPLET TAPEZ 2');
               writeln;
               writeln;
               writeln;
               writeln;
               writeln;
               writeln('':15,'FAITES VOTRE CHOIX:');
               readln(choix);
         until (choix>=1) and (choix<=2);
         clrscr;
    end;
     
     
    Procedure expediteur;
     var nom2,prenom2:string;
    begin
     writeln('COMBIEN DE MESSAGES VOULEZ VOUS SAISIR?');
       if (m <= n) then
         begin
           readln(m);
         end
         else
           begin
             writeln('LE NOMBRE DE MESSAGE NE DOIT PAS DEPASSER',n,'!!!');
           end;
     for i:=1 to m do
      begin
         with p do
          begin
              writeln('NOM EXPEDITEUR',i,' : ');readln(nom2);
              writeln('PRENOM EXPEDITEUR',i,' : ');readln(prenom2);
          end;
      end;
    end;
     
     
    Procedure destinataire;
     var nom1,prenom1:string;
    begin
     for i:=1 to m do
      begin
         with p do
         begin
              writeln('NOM DESTINATAIRE',i,' : ');readln(nom1);
              writeln('PRENOM DESTINATAIRE',i,' : ');readln(prenom1);
         end;
      end;
    end;
     
     
    procedure date;
    begin
     for i:=1 to m do
      begin
         with d do
         begin
              writeln('SAISIE DE LA DATE');
              writeln('JOUR:');readln(d.jour);
              writeln('MOIS:');readln(d.mois);
              writeln('ANNEE:');readln(d.annee);
              writeln('LA DATE EST:',d.jour,'/',d.mois,'/',d.annee);
         end;
      end;
    end;
     
     
    procedure content;
    var cont:string;
    begin
      for i:=1 to m do
           begin
             writeln('SAISISSEZ LE CONTENU DU',i,' EME MESSAGE ');readln(cont);
             writeln('YA T-IL DES PIECES A JOINDRE? oui/non');readln(rep);
           end;
    end;
     
     
    Procedure affiche;
    var cont,nom1,nom2,prenom1,prenom2:string;
    begin
     for i:=1 to m do
      begin   writeln;
              writeln('':20,'MESSAGE Nø',i);
              with t[i] do
                    begin
                         with p do
                              begin
                                   writeln;
                                   writeln('':20,'EXPEDITEUR:',prenom2,' ',nom2);
                                   writeln;
                                   writeln('':20,'DESTINATAIRE:',prenom1,' ',nom1);
                                   writeln;
                                   writeln('':20,'DATE:',d.jour,'/',d.mois,'/',d.annee);
                                   writeln;
                                   writeln('':20,'MESSAGE:',cont);
                                   writeln;
                                   writeln('':20,'PIECE JOINTE:',rep);
                                   writeln;
     
                              end;
                    end;
      end;
    end;
     
     
     
    Begin
    textmode(2);
    textcolor(white);textbackground(magenta);clrscr;
     clrscr;
    begin
         repeat
               menu;
     
               case choix of
                    1:begin
                           expediteur;
                           destinataire;
                           date;
                           content;
                      end;
                    2:begin
                           affiche;
                      end;
               end;
               writeln('VOULEZ VOUS CONTINUER o/n');
               readln(reponse1);
         until (reponse1 ='n');
    end;
    end.
    Fichiers attachés Fichiers attachés

  2. #2
    Membre expérimenté Avatar de Tux++
    Étudiant
    Inscrit en
    Avril 2008
    Messages
    281
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2008
    Messages : 281
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    procedure content;
    var cont:string;
    begin
      for i:=1 to m do
           begin
             writeln('SAISISSEZ LE CONTENU DU',i,' EME MESSAGE ');readln(cont);
             writeln('YA T-IL DES PIECES A JOINDRE? oui/non');readln(rep);
           end;
    end;
    C'est normal vu que tu ne sauves pas tes variables avant de les écraser,
    il faudrait par exemple rejouter un tab_messages[i].cont := cont;
    Et même chose pour rep, à chaque itération du for, sinon tu ne gardes que la dernière valeur

  3. #3
    Expert confirmé

    Inscrit en
    Août 2006
    Messages
    3 967
    Détails du profil
    Informations forums :
    Inscription : Août 2006
    Messages : 3 967
    Par défaut
    Hia,

    Je n'ai pas lu, à peine survolé, cause usage et abus de variables globales.

    Il faut apprendre à passer des paramètres aux procédures/fonctions, et à utiliser des fonctions au lieu de procédures quand on doit renvoyer une valeur (par exemple la procédure menu serait avantageusement remplacée par une fonction qui renverra le choix effectué...).

    Quand tu définis des types, inutile de répéter le mot-clé type devant chaque définition (sinon, pourquoi ne pas le faire pour const et var ?)

    Une petite mise en forme du code, régulière et cohérente ne fait pas de mal non plus (pas besoin de tant décaler comme tu le fais, il suffit que ce soit assez pour être visible sans se crever les yeux sur l'écran).
    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
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    program fanta;
     
    uses crt;
     
    type 
      personne = record
        nom1, prenom1, nom2, prenom2: string;
      end;
     
      dates = record
        jour, mois, annee: Integer;
      end;
     
      reponse = record
        oui, non: string;
      end;
     
      message = record
        expediteur, destinataire: personne;
        contenu : string;
        Date : dates;
        piece_jointe : reponse;
      end;
     
    const 
      n = 10;
     
    var 
      t : array[1..n] of message;
      i, m, choix : Integer;
      p : personne;
      pic : reponse;
      d : dates;
      nom1, nom2, prenom1, prenom2, rep, reponse1 : string;
     
    procedure Menu;
    begin
      repeat
        Writeln;
        Writeln;
        Writeln;
        Writeln;
        Writeln;
        Writeln('': 15,'1:POUR LA SAISIE D''UN MESSAGE TAPEZ 1');
        Writeln;
        Writeln;
        Writeln;
        Writeln;
        Writeln;
        Writeln('': 15,'2:POUR VOIR LE MESSAGE AU COMPLET TAPEZ 2');
        Writeln;
        Writeln;
        Writeln;
        Writeln;
        Writeln;
        Writeln('': 15,'FAITES VOTRE CHOIX:');
        Readln(choix);
      until (choix >= 1) and (choix <= 2);
      clrscr;
    end;
     
    procedure expediteur;
    var 
      nom2, prenom2 : string;
    begin
      Writeln('COMBIEN DE MESSAGES VOULEZ VOUS SAISIR?');
      if (m <= n) then
      begin
        Readln(m);
      end
      else
      begin
        Writeln('LE NOMBRE DE MESSAGE NE DOIT PAS DEPASSER', n, '!!!');
      end;
      for i := 1 to m do
      begin
        with p do
        begin
          Writeln('NOM EXPEDITEUR', i, ' : ');
          Readln(nom2);
          Writeln('PRENOM EXPEDITEUR', i, ' : ');
          Readln(prenom2);
        end;
      end;
    end;
     
    procedure destinataire;
    var 
      nom1, prenom1 : string;
    begin
      for i := 1 to m do
      begin
        with p do
        begin
          Writeln('NOM DESTINATAIRE', i, ' : ');
          Readln(nom1);
          Writeln('PRENOM DESTINATAIRE', i, ' : ');
          Readln(prenom1);
        end;
      end;
    end;
     
    procedure Date;
    begin
      for i := 1 to m do
      begin
        with d do
        begin
          Writeln('SAISIE DE LA DATE');
          Writeln('JOUR:');
          Readln(d.jour);
          Writeln('MOIS:');
          Readln(d.mois);
          Writeln('ANNEE:');
          Readln(d.annee);
          Writeln('LA DATE EST:', d.jour, '/', d.mois, '/', d.annee);
        end;
      end;
    end;
     
    procedure content;
    var 
      cont : string;
    begin
      for i := 1 to m do
      begin
        Writeln('SAISISSEZ LE CONTENU DU', i, ' EME MESSAGE ');
        Readln(cont);
        Writeln('YA T-IL DES PIECES A JOINDRE? oui/non');
        Readln(rep);
      end;
    end;
     
    procedure affiche;
    var 
      cont, nom1, nom2, prenom1, prenom2 : string;
    begin
      for i := 1 to m do
      begin   
        Writeln;
        Writeln('': 20,'MESSAGE Nø', i);
        with t[i] do
        begin
          with p do
          begin
            Writeln;
            Writeln('': 20,'EXPEDITEUR:', prenom2, ' ', nom2);
            Writeln;
            Writeln('': 20,'DESTINATAIRE:', prenom1, ' ', nom1);
            Writeln;
            Writeln('': 20,'DATE:', d.jour, '/', d.mois, '/', d.annee);
            Writeln;
            Writeln('': 20,'MESSAGE:', cont);
            Writeln;
            Writeln('': 20,'PIECE JOINTE:', rep);
            Writeln;
          end;
        end;
      end;
    end;
     
    begin
      textmode(2);
      textcolor(white);
      textbackground(magenta);
      clrscr;
      clrscr;
      begin
        repeat
          Menu;
     
          case choix of
            1:
              begin
                expediteur;
                destinataire;
                Date;
                content;
              end;
            2:
              begin
                affiche;
              end;
          end;
          Writeln('VOULEZ VOUS CONTINUER o/n');
          Readln(reponse1);
        until (reponse1 = 'n');
      end;
    end.

  4. #4
    Membre à l'essai
    Inscrit en
    Mai 2008
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 4
    Par défaut
    Salut à vous tous qui avez pris le temps de me répondre. Mais Tux++ est-ce que tu pourrais m'aider davantage parsque, d'habitude, avec les enregitrements on n'utilise que les caractéristiques de cet enregistrement. Je vous renvoie la version améliorée un peu, Aidez-moi je suis à court d'idées,
    Fichiers attachés Fichiers attachés

  5. #5
    Rédacteur
    Avatar de darrylsite
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    1 299
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2007
    Messages : 1 299
    Par défaut
    C' est ton jour de chance.
    Voici ton code arrangé :
    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
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
     
    program fanta;
    uses crt;
     
    type personne=record
                   nom,prenom : string;
                  end;
     
         dates=record
                 jour,mois,annee:integer;
               end;
     
         message=record
                  expediteur,destinataire : personne;
                  contenu:string;
                  date:dates;
                  piece_jointe:string[3];
                end;
     
    const N=10;
    var t:array[1..N] of message;
     {-----------------------------------------------------------------}
    function menu :integer ;
     var choix:integer;
    begin
         repeat
               writeln;
               writeln;
               writeln;
               writeln;
               writeln;
               writeln('':15,'1:POUR LA SAISIE D''UN MESSAGE TAPEZ 1');
               writeln;
               writeln;
               writeln;
               writeln;
               writeln;
               writeln('':15,'2:POUR VOIR LE MESSAGE AU COMPLET TAPEZ 2');
               writeln;
               writeln;
               writeln;
               writeln;
               writeln;
               writeln('':15,'FAITES VOTRE CHOIX:');
               readln(choix);
         until (choix>=1) and (choix<=2);
         clrscr;
         menu:=choix;
    end;
     
    {-----------------------------------------------------------------} 
     
    Procedure expediteur(var m: integer);
      var i : integer;
      begin
     
     writeln('COMBIEN DE MESSAGES VOULEZ VOUS SAISIR?');
      repeat   
          readln(m);
         if (m>n) then
          writeln('LE NOMBRE DE MESSAGE NE DOIT PAS DEPASSER ',n,' !!!');
      until m<=n;
     
     for i:=1 to m do
      begin
         with t[i].expediteur do
          begin
              writeln('NOM EXPEDITEUR ',i,' : '); 
              readln(nom);
              writeln('PRENOM EXPEDITEUR',i,' : '); 
              readln(prenom);
          end;
      end;
    end;
     
    {-----------------------------------------------------------------}
     
    Procedure destinataire(m: integer);
     var i :integer;
     begin
     for i:=1 to m do
      begin
         with t[i].destinataire do
         begin
              writeln('NOM DESTINATAIRE ',i,' : ');readln(nom);
              writeln('PRENOM DESTINATAIRE ',i,' : ');readln(prenom);
         end;
      end;
    end;
     
    {-----------------------------------------------------------------} 
     procedure date(m: integer);
      var i:integer;
    begin
     for i:=1 to m do
      begin
         with t[i].date do
         begin
              writeln('SAISIE DE LA DATE');
              writeln('JOUR:');   readln(jour);
              writeln('MOIS:');   readln(mois);
              writeln('ANNEE:'); readln(annee);
              writeln('LA DATE EST: ',jour,'/',mois,'/',annee);
         end;
      end;
    end;
    {-----------------------------------------------------------------} 
     
    procedure content(m: integer);
    var i:integer;
    begin
     
      for i:=1 to m do
       with t[i] do
           begin
             writeln('SAISISSEZ LE CONTENU DU ',i,' EME MESSAGE '); readln(contenu);
             writeln('YA T-IL DES PIECES A JOINDRE? oui/non');readln(piece_jointe);
           end;
    end;
     
     {-----------------------------------------------------------------} 
     
    Procedure affiche(m:integer);
     var i:integer;
    begin
     for i:=1 to m do
      begin   writeln;
              writeln('':20,'MESSAGE Nø',i);
              with t[i] do
                    begin
                              begin
                                   writeln;
                                   writeln('':20,'EXPEDITEUR:',expediteur.prenom,' ',expediteur.nom);
                                   writeln;
                                   writeln('':20,'DESTINATAIRE:',destinataire.prenom,' ',destinataire.nom);
                                   writeln;
                                   writeln('':20,'DATE:',date.jour,'/',date.mois,'/',date.annee);
                                   writeln;
                                   writeln('':20,'MESSAGE:',contenu);
                                   writeln;
                                   writeln('':20,'PIECE JOINTE:',piece_jointe);
                                   writeln;
     
                              end;
                    end;
      end;
    end;
    {-----------------------------------------------------------------} 
     
     var m:integer;
         reponse1:char;
    Begin
     
     
    clrscr;
    m:=0;
    begin
         repeat
     
               case menu of
                    1:begin
                           expediteur(m);
                           destinataire(m);
                           date(m);
                           content(m);
                      end;
                    2:begin
                           affiche(m);
                      end;
               end;
     
               writeln('VOULEZ VOUS CONTINUER o/n');
               readln(reponse1);
         until (reponse1 ='n');
    end;
    end.

  6. #6
    Membre à l'essai
    Inscrit en
    Mai 2008
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Mai 2008
    Messages : 4
    Par défaut
    MERCI MERCI MERCI MERCI tu m'as sauvé la vie je tadore merci merci bocou et bne continuation

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 9
    Dernier message: 08/02/2008, 16h17
  2. [delphi7][access][ado]pb d'affichage des enregistrements
    Par alibabas dans le forum Bases de données
    Réponses: 8
    Dernier message: 29/07/2006, 18h46
  3. Réponses: 8
    Dernier message: 28/03/2006, 16h52
  4. []Problème d'affichage des enregistrements dans un DataReport
    Par GeniuZ dans le forum VB 6 et antérieur
    Réponses: 8
    Dernier message: 05/01/2005, 16h52
  5. Réponses: 3
    Dernier message: 29/12/2003, 13h47

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