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

  1.                                        -- Chapter 3 - Program 5
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure IntAttrs is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    type BUG_RANGE is range -13..34;
  11.  
  12.    Rat : INTEGER;
  13.    Dog : NATURAL;
  14.    Cat : POSITIVE;
  15.    Bug : BUG_RANGE;
  16.  
  17. begin
  18.  
  19.    Rat := 12;
  20.    Dog := 23;
  21.    Cat := 31;
  22.    Bug := -11;
  23.  
  24.    Put("The type INTEGER uses ");
  25.    Put(INTEGER'SIZE);
  26.    Put(" bits of memory,");
  27.    New_Line;
  28.    Put(" and has a range from ");
  29.    Put(INTEGER'FIRST);
  30.    Put(" to ");
  31.    Put(INTEGER'LAST);
  32.    New_Line;
  33.    Put(" Rat has a present value of ");
  34.    Put(Rat);
  35.    New_Line(2);
  36.  
  37.    Put("The type NATURAL uses ");
  38.    Put(NATURAL'SIZE);
  39.    Put(" bits of memory,");
  40.    New_Line;
  41.    Put(" and has a range from ");
  42.    Rat := NATURAL'FIRST;
  43.    Put(Rat);
  44.    Put(" to ");
  45.    Rat := NATURAL'LAST;
  46.    Put(Rat);
  47.    New_Line;
  48.    Put(" Dog has a present value of ");
  49.    Put(Dog);
  50.    New_Line(2);
  51.  
  52.    Put("The type POSITIVE uses ");
  53.    Put(POSITIVE'SIZE);
  54.    Put(" bits of memory,");
  55.    New_Line;
  56.    Put(" and has a range from ");
  57.    Put(POSITIVE'FIRST);
  58.    Put(" to ");
  59.    Put(POSITIVE'LAST);
  60.    New_Line;
  61.    Put(" Cat has a present value of ");
  62.    Put(Cat);
  63.    New_Line(2);
  64.  
  65.    Put("The type BUG_RANGE uses ");
  66.    Put(INTEGER(BUG_RANGE'SIZE));
  67.    Put(" bits of memory,");
  68.    New_Line;
  69.    Put(" and has a range from ");
  70.    Put(INTEGER(BUG_RANGE'FIRST));
  71.    Put(" to ");
  72.    Put(INTEGER(BUG_RANGE'LAST));
  73.    New_Line;
  74.    Put(" Bug has a present value of ");
  75.    Put(INTEGER(Bug));
  76.    New_Line(2);
  77.  
  78. end IntAttrs;
  79.  
  80.  
  81.  
  82.  
  83. -- Result of execution
  84.  
  85. -- The type INTEGER uses     16 bits of memory
  86. --  and has a range from -32768 to  32767
  87. --  Rat has a present value of     12
  88.  
  89. -- The type NATURAL uses     16 bits of memory
  90. --  and has a range from      0 to  32767
  91. --  Dog has a present value of     23
  92.  
  93. -- The type POSITIVE uses     16 bits of memory
  94. --  and has a range from      1 to  32767
  95. --  Cat has a present value of     31
  96.  
  97. -- The type BUG_RANGE uses     16 bits of memory
  98. --  and has a range from    -13 to     34
  99. --  Bug has a present value of    -11
  100.  
  101.