.
..
exo01a.adb (download) (view)
exo02a.adb (download) (view)
exo03.adb (download) (view)
exo04.adb (download) (view)

-- put et get
with Ada.Text_Io;
use  Ada.Text_Io;

procedure Exo02a is
   -- exo 2a
   subtype T_Couleur_Primaire is Natural range 0..255;
   type T_Couleur is record
      Red   : T_Couleur_Primaire;
      Green : T_Couleur_Primaire;
      Blue  : T_Couleur_Primaire;
   end record;

   -- exo 2b
   White : constant T_Couleur := (Red => 255, Green => 255, Blue => 255);
   Black : constant T_Couleur := (0, 0, 0);
   Red   : constant T_Couleur := (255, 0, 0);
   Green : constant T_Couleur := (0, 255, 0);
   Blue  : constant T_Couleur := (0, 0, 255);
   Orange: constant T_Couleur := (255, 128, 0);

   -- exo 2c
   function "<"(C1, C2 : T_Couleur) return boolean is
   begin
      return (C1.Red < C2.Red)
        or (C1.Red = C2.Red and C1.Green < C2.Green)
        or (C1.Red = C2.Red and C1.Green = C2.Green and C1.Red < C2.Red);
   end;

   -- exo 2d
   type T_Compare is (Less, Equal, Greater);
   function Compare(C1, C2 : T_Couleur) return T_Compare is
   begin
      if C1 = C2 then
         return Equal;
      elsif C1 < C2 then
         return Less;
      else
         return Greater;
      end if;
   end;

begin
   Put("Red < Red : ");
   Put_Line(Boolean'Image  ( Red   < Red));

   Put("Red < White : ");
   Put_Line(Boolean'Image  ( Red   < White));

   Put("White < Red : ");
   Put_Line(Boolean'Image  ( White < Red));

   ----------------------------------------------

   Put("White ");
   Put(T_Compare'Image(Compare(White, White)));
   Put_Line(" White");

   Put("Red ");
   Put(T_Compare'Image(Compare(Red,   White)));
   Put_Line(" White");

   Put("White ");
   Put(T_Compare'Image(Compare(White, Red)));
   Put_Line(" Red");
end;
 
Webmaster : pierrefrancois.leon@laposte.net

Valid XHTML 1.0 Strict Valid CSS!