home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog2 / answers / ch15_2.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  4.1 KB  |  115 lines

  1.                        -- Chapter 15 - Programming example 2
  2. with Text_IO;
  3.  
  4. procedure CH15_2 is
  5.  
  6.    type MY_FIXED is delta 0.01 range 20.0..42.0;
  7.    type DAY is (MON, TUE, WED, THU, FRI, SAT, SUN);
  8.    type MY_INTEGER is range -13..323;
  9.  
  10.    X_Value : FLOAT := 3.14;
  11.    Index   : INTEGER := 27;
  12.    Count   : MY_INTEGER;
  13.    What    : BOOLEAN := TRUE;
  14.    Who     : BOOLEAN := FALSE;
  15.    Size    : MY_FIXED := 24.33;
  16.    Today   : DAY := TUE;
  17.  
  18.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  19.    package Flt_IO is new Text_IO.Float_IO(FLOAT);
  20.    package Enum_IO is new Text_IO.Enumeration_IO(BOOLEAN);
  21.  
  22.    package Fix_IO is new Text_IO.Fixed_IO(MY_FIXED);
  23.    package Day_IO is new Text_IO.Enumeration_IO(DAY);
  24.    package New_Int_IO is new Text_IO.Integer_IO(MY_INTEGER);
  25.  
  26. begin
  27.                                        -- INTEGER outputs
  28.    Text_IO.Put("Index is --->"); Int_IO.Put(Index);
  29.               Text_IO.Put("<---"); Text_IO.New_Line;
  30.    Text_IO.Put("Index is --->"); Int_IO.Put(Index,3);
  31.               Text_IO.Put("<---"); Text_IO.New_Line;
  32.    Text_IO.Put("Index is --->"); Int_IO.Put(Index,8);
  33.               Text_IO.Put("<---"); Text_IO.New_Line(2);
  34.  
  35.                                        -- FLOAT outputs
  36.    Text_IO.Put("Put(X_Value) -------->"); Flt_IO.Put(X_Value);
  37.               Text_IO.New_Line;
  38.    Text_IO.Put("Put(X_Value,5) ------>"); Flt_IO.Put(X_Value,5);
  39.               Text_IO.New_Line;
  40.    Text_IO.Put("Put(X_Value,5,5) ---->"); Flt_IO.Put(X_Value,5,5);
  41.               Text_IO.New_Line;
  42.    Text_IO.Put("Put(X_Value,5,5,0) -->"); Flt_IO.Put(X_Value,5,5,0);
  43.               Text_IO.New_Line(2);
  44.  
  45.                                        -- MY_FIXED outputs
  46.    Text_IO.Put("Put(Size) -------->"); Fix_IO.Put(Size);
  47.               Text_IO.New_Line;
  48.    Text_IO.Put("Put(Size,5) ------>"); Fix_IO.Put(Size,5);
  49.               Text_IO.New_Line;
  50.    Text_IO.Put("Put(Size,5,5) ---->"); Fix_IO.Put(Size,5,5);
  51.               Text_IO.New_Line;
  52.    Text_IO.Put("Put(Size,5,5,0) -->"); Fix_IO.Put(Size,5,5,0);
  53.               Text_IO.New_Line(2);
  54.  
  55.                                        -- BOOLEAN outputs
  56.    Text_IO.Put("What is ---->"); Enum_IO.Put(What);
  57.               Text_IO.Put("<---"); Text_IO.New_Line;
  58.    Text_IO.Put("Who is ----->"); Enum_IO.Put(Who);
  59.               Text_IO.Put("<---"); Text_IO.New_Line;
  60.    Text_IO.Put("What is ---->"); Enum_IO.Put(What,7);
  61.               Text_IO.Put("<---"); Text_IO.New_Line;
  62.    Text_IO.Put("Who is ----->"); Enum_IO.Put(Who,8);
  63.               Text_IO.Put("<---"); Text_IO.New_Line;
  64.    Text_IO.Put("TRUE is ---->"); Enum_IO.Put(TRUE);
  65.               Text_IO.Put("<---"); Text_IO.New_Line;
  66.    Text_IO.Put("FALSE is --->"); Enum_IO.Put(FALSE);
  67.               Text_IO.Put("<---"); Text_IO.New_Line(2);
  68.  
  69.                                        -- Enumeration outputs
  70.    Text_IO.Put("Today is --->"); Day_IO.Put(Today);
  71.               Text_IO.Put("<---"); Text_IO.New_Line;
  72.    Text_IO.Put("Today is --->"); Day_IO.Put(Today,6);
  73.               Text_IO.Put("<---"); Text_IO.New_Line;
  74.    Text_IO.Put("Today is --->"); Day_IO.Put(Today,7);
  75.               Text_IO.Put("<---"); Text_IO.New_Line;
  76.    Text_IO.Put("WED is ----->"); Day_IO.Put(WED);
  77.               Text_IO.Put("<---"); Text_IO.New_Line;
  78.    Text_IO.Put("WED is ----->"); Day_IO.Put(WED,5);
  79.               Text_IO.Put("<---"); Text_IO.New_Line(2);
  80.  
  81. end CH15_2;
  82.  
  83.  
  84.  
  85.  
  86. -- Result of execution
  87.  
  88. -- Index is --->    27<---
  89. -- Index is ---> 27<---
  90. -- Index is --->      27<---
  91. --
  92. -- Put(X_Value) --------> 3.14000000000000E+00
  93. -- Put(X_Value,5) ------>    3.14000000000000E+00
  94. -- Put(X_Value,5,5) ---->    3.14000E+00
  95. -- Put(X_Value,5,5,0) -->    3.14000
  96. --
  97. -- Put(Size) --------> 24.33
  98. -- Put(Size,5) ------>   24.33
  99. -- Put(Size,5,5) ---->   24.32813
  100. -- Put(Size,5,5,0) -->   24.32813
  101. --
  102. -- What is ---->TRUE<---
  103. -- Who is ----->FALSE<---
  104. -- What is ---->TRUE   <---
  105. -- Who is ----->FALSE   <---
  106. -- TRUE is ---->TRUE<---
  107. -- FALSE is --->FALSE<---
  108. --
  109. -- Today is --->TUE<---
  110. -- Today is --->TUE   <---
  111. -- Today is --->TUE    <---
  112. -- WED is ----->WED<---
  113. -- WED is ----->WED  <---
  114.  
  115.