J'ai un exemple de manuel modifié comme suit (le livre est de comprendre Ada --- une approche d'ingénierie logicielle par Bray et Pokrass):Ada: comment accéder à cette variable?
PACKAGE SOLAR_SYSTEM IS
TYPE PLANET IS (MERCURY, VENUS, MARS, JUPITER, SATURN, NEPTUNE);
SUBTYPE TERRESTRIAL_PLANET IS PLANET RANGE MERCURY..MARS;
SUBTYPE JOVIAN_PLANET IS PLANET RANGE JUPITER..NEPTUNE;
TYPE MILES IS DIGITS 5 RANGE 0.0..5.0E9;
TYPE PLANET_FACTS IS ARRAY (PLANET) OF MILES;
DISTANCE_TO_SUN : CONSTANT PLANET_FACTS :=
(MERCURY => 36.0E6, VENUS => 67.2E6, MARS => 141.7E6,
JUPITER => 484.0E6, SATURN => 887.0E6, NEPTUNE => 2797.0E6);
NUMBER_OF_MOONS: CONSTANT ARRAY (PLANET) OF NATURAL :=
(MERCURY => 0, VENUS => 0, MARS => 2,
JUPITER => 12, SATURN => 10, NEPTUNE => 2);
END SOLAR_SYSTEM;
Maintenant, pour accéder à certaines variables et leur contenu,
WITH Ada.Float_Text_IO;
WITH Ada.Text_IO;
WITH Ada.Integer_Text_IO;
WITH SOLAR_SYSTEM;
USE SOLAR_SYSTEM;
PROCEDURE TEST2 IS
BEGIN -- main program
Ada.Integer_Text_IO.Put(Item => NUMBER_OF_MOONS(Saturn));
Ada.Text_IO.New_Line;
Ada.Float_Text_IO.Put(Item => DISTANCE_TO_SUN(Saturn));
END TEST2;
Je peux accéder à NUMBER_OF_MOONS (Saturne) sans aucun problème mais j'ai de la difficulté à accéder à DISTANCE_TO_SUN (Saturne). Comment y accéder?
merci beaucoup ...
ce que je reçois sur la compilation avec la déclaration
Ada.Float_Text_IO.Put(Item => DISTANCE_TO_SUN(Saturn));
fichier de liste:
1. WITH Ada.Float_Text_IO;
|
>>> warning: no entities of "FLOAT_TEXT_IO" are referenced
2. WITH Ada.Text_IO;
3. WITH Ada.Integer_Text_IO;
4. WITH SOLAR_SYSTEM;
5. USE SOLAR_SYSTEM;
6.
7.
8. PROCEDURE TEST2 IS
9.
10. BEGIN -- main program
11. Ada.Integer_Text_IO.Put(Item => NUMBER_OF_MOONS(Saturn));
12. Ada.Text_IO.New_Line;
13. Ada.Float_Text_IO.Put(Item => DISTANCE_TO_SUN(Saturn));
1 5
>>> no candidate interpretations match the actuals:
>>> missing argument for parameter "To" in call to "PUT" declared at a-tiflio.ads:81, instance at a-flteio.ads:20
>>> missing argument for parameter "File" in call to "PUT" declared at a-tiflio.ads:63, instance at a-flteio.ads:20
>>> possible missing instantiation of Text_IO.Float_IO
>>> expected type "Standard.Float"
>>> found type "MILES" defined at solar_system.ads:8
>>> ==> in call to "Put" at a-tiflio.ads:70, instance at a-flteio.ads:20
14. END TEST2;
Le problème est que DISTANCE_TO_SUN (Saturne) est de type MILES qui est l'un des types à virgule flottante. Donc, simplement utiliser Ada.Float_Text_IO.Put ne fonctionnera pas.
Quel message erreur que vous obtenez lorsque vous essayez d'accéder 'DISTANCE_TO_SUN (Saturn)'? – kiamlaluno
Merci. Je vais mettre le fichier de la liste dans mon message. – yCalleecharan