Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1091 connectés 

  FORUM HardWare.fr
  Programmation
  Ada

  table de vérité

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

table de vérité

n°1234539
Profil sup​primé
Posté le 30-10-2005 à 17:42:42  answer
 

Comment faire pour afficher la table de vérité de l'expression booléenne suivante :  
                       A and (B or C)
 
J'ai commencé qqch. Pouvez vous me dire ce que vous en pensez?
 
with ada.text_io, ada.integer_text_io;
A,B,C : boolean;
if A = true then
   if B = true then
      ada.text_io.put("A and(B or C)=" );ada.text_io.put("vrai" );
   else
      if C = true then
         ada.text_io.put("A and(B or C)=" );ada.text_io.put("vrai" );
      else
         ada.text_io.put("A and(B or C)=" );ada.text_io.put("faux" );
      end if;
   end if;
else
   ada.text_io.put("A and(B or C)=" );ada.text_io.put("faux" );
end if;
 
Merci

mood
Publicité
Posté le 30-10-2005 à 17:42:42  profilanswer
 

n°1234550
Pillow
'cos the trees won't talk
Posté le 30-10-2005 à 18:25:44  profilanswer
 

En ADA, il y a quelque chose de bien utile : use.
 
Tu peux remplacer

with ada.text_io;
ada.text_io.put("toto" );


par

with ada.text_io;
use ada.text_io;
ada.text_io.put("toto" );


 
Dans A = True, true est redondant : A tout seul est évalué correctement (mais explicter le test peut être un choix stylistique).
 
En ADA, tu disposes de and et de or. Toute la logique de ton bout de code peut être écrit ainsi :

if A and (B or C)
   then put ("vrai" );
   else put ("faux" );
end if;

Ce qui est légerement plus simple ;)  
 
 
 
Est ce que tu sais ce qu'est une table de vérité ? Cela ressemble à ça

A      B      C     A and (B or C)
0      0      0        0
0      0      1        0
0      1      0        0
 
       ...(etc)...
 
1      1      0        1
1      1      1        1

 
 
Pour ton exercice, il te faut calculer la valeur de A and (B or C) pour toute les combinaisons binaires de A, B et C possibles et afficher la ligne correspondante. Tu veux évaluer l'expression pour chacune de ces lignes :
ABC
 
000
001
010
011
100
101
110
111
 
Regarde attentivement les valeurs de chacune des colonnes. Le troisième bit est alternativement à 0 et à 1; le deuxième bit est alternativement deux fois à 0 puis deux fois à 1; le premier bit est quant à lui quatre fois à 0 puis quatre fois à 1. Qu'est ce que cela t'inspire ?


Message édité par Pillow le 30-10-2005 à 18:37:54
n°1234553
Profil sup​primé
Posté le 30-10-2005 à 18:40:17  answer
 

Merci beaucoup pour ta réponse.
Je comprends ce qu'il faut faire cad afficher la table de vérité comme tu l'as écrite. Par contre je ne vois pas comment le faire en ADA.
J'ai pensé à un tableau mais ça ne m'aide pas...

n°1234600
Pillow
'cos the trees won't talk
Posté le 30-10-2005 à 20:15:25  profilanswer
 

Exemple:

for A in boolean loop
    for B in boolean loop
        if A then Put (1); else Put (0); end if;
        if B then Put (1); else Put (0); end if;
        New_Line;
    end;
end;

Affichera :
0       0
0       1
1       0
1       1

n°1234879
Profil sup​primé
Posté le 31-10-2005 à 11:52:18  answer
 

J'ai modifier mon programme. Celui ci m'affichera, je pense, ma table de vérité comme ceci :
A  B  C  A and (B or C)
1  1  1  1
1  1  0  1
1  0  1  1
1  0  0  0
0  1  1  0
0  1  0  0
0  0  1  0
0  0  0  0  
 

with ada.text_io, ada.integer_text_io;
A,B,C : boolean;
begin
   ada.text_io.put("A" ); ada.text_io.put("B" ); ada.text_io.put("C" );
   ada.text_io.put("A and (B or C" );
   ada.text_io.new_line;
   for A loop
      for B loop
         for C loop
           if A then ada.text_io.put("1" ); else ada.text_io.put("0" ); end if;
           if B then ada.text_io.put("1" ); else ada.text_io.put("0" ); end if;
           if C then ada.text_io.put("1" ); else ada.text_io.put("0" ); end if;
           if A and (B or C) then ada.text_io.put("1" ); else ada.text_io.put("0" );  
           end if;
            ada.text_io.new_line;    
         end;
      end;
   end;
end;


qu'en pensez vous?

Message cité 1 fois
Message édité par Profil supprimé le 31-10-2005 à 11:52:57
n°1234928
Pillow
'cos the trees won't talk
Posté le 31-10-2005 à 12:26:44  profilanswer
 

Ce sera probablement le contraire (0 0 0 0 en premier).
 
 

Citation :


with ada.text_io, ada.integer_text_io;
A,B,C : boolean;
begin
   ada.text_io.put("A" ); ada.text_io.put("B" ); ada.text_io.put("C" );
   ada.text_io.put("A and (B or C" );
   ada.text_io.new_line;
   for A loop
      for B loop
         for C loop
           if A then ada.text_io.put("1" ); else ada.text_io.put("0" ); end if;
           if B then ada.text_io.put("1" ); else ada.text_io.put("0" ); end if;
           if C then ada.text_io.put("1" ); else ada.text_io.put("0" ); end if;
           if A and (B or C) then ada.text_io.put("1" ); else ada.text_io.put("0" );  
           end if;
            ada.text_io.new_line;    
         end;
      end;
   end;
end;


qu'en pensez vous?

Deux choses "graves" :
- une boucle for se termine par end loop et non pas par end.
- Il faut une unité de compilation. Par exemple :

with ada.text_io, ada.integer_text_io;
procedure table_verite is
  Une_Variable : integer;
begin
   ada.text_io.put("A" ); ada.text_io.put("B" ); ada.text_io.put("C" );
   (...)
end;


 
 
Les choses moins importantes :  
- Put ("A" ) ne rajoute pas d'espaces. il faut que tu en ajoutes toi même.
- A, B et C étant des variables de boucles, il n'y a pas besoin de les déclarer : ADA le fait implicitement.

n°1234947
Profil sup​primé
Posté le 31-10-2005 à 12:53:20  answer
 

Je n'ai pas très bien compris l'unité de compilation.
 
Mais maintenant est ce correct ?
 

with ada.text_io, ada.integer_text_io;
A,B,C : boolean;
une_variable : integer;
begin
   ada.text_io.put("A " ); ada.text_io.put("B " ); ada.text_io.put("C " );
   ada.text_io.put("A and (B or C" );
   ada.text_io.new_line;
   for A loop
      for B loop
         for C loop
           if A then ada.text_io.put("1" ); else ada.text_io.put("0" ); end if;
           if B then ada.text_io.put("1" ); else ada.text_io.put("0" ); end if;
           if C then ada.text_io.put("1" ); else ada.text_io.put("0" ); end if;
           if A and (B or C) then ada.text_io.put("1" ); else ada.text_io.put("0" );  
           end if;
           ada.text_io.new_line;    
         end loop;
      end loop;
   end loop;
end;


n°1234960
Pillow
'cos the trees won't talk
Posté le 31-10-2005 à 13:28:01  profilanswer
 

Ada ne compile que des unités de compilation. Une unité de compilation peut être un package (qui contient des fonctions qui peuvent être réutilisée plus tard dans un autre programme) ou un sous-programme.
 
Le programme minimal pour afficher un message en Ada :

with Ada.Text_IO;
use Ada.Text_IO;
 
procedure Hello is
begin
    Put_Line ("Elo ouorld" );
end;

Ça, c'est une unité de compilation correcte. Tu ne peux pas mettre un Put_Line en dehors du corps de la procédure Hello.
 
 

n°1234963
Profil sup​primé
Posté le 31-10-2005 à 13:31:11  answer
 

Dans cet exercice je ne dois utiliser ni procédures, ni use.

n°1234969
masklinn
í dag viðrar vel til loftárása
Posté le 31-10-2005 à 13:44:08  profilanswer
 

L'ADA ne permet pas d'afficher directement les booléens?


---------------
Stick a parrot in a Call of Duty lobby, and you're gonna get a racist parrot. — Cody
mood
Publicité
Posté le 31-10-2005 à 13:44:08  profilanswer
 

n°1235045
Pillow
'cos the trees won't talk
Posté le 31-10-2005 à 14:56:47  profilanswer
 

masklinn a écrit :

L'ADA ne permet pas d'afficher directement les booléens?


A ma connaissance, il n'y a pas de Put qui marche directement avec des booléens, si c'était la question.  
 
Par contre on peut bien sûr faire ça :

Ada.Integer_Text_IO.Put (Boolean'Pos(un_booleen));

Et bien sûr, écrire une procédure d'output pour les booléens est trivial.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Ada

  table de vérité

 

Sujets relatifs
Sybase : Vérifier l'existence d'une table dans le tempdbafficher la derniere entrée peu importe la table ?!
taille d'une table en SQLpb d'utilisation table de hashage
Probleme ecriture sur table attaché AS400[SQL] ALTER TABLE sur table liée ?? ou solution de contournement plz ?
Mettre le nom d'une table en paramètre dans un script SqlLister les colonnes d'une table
Insérer fichier dans table sqlalgebre de boules et table de verité
Plus de sujets relatifs à : table de vérité


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR