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

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