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

  1.                           -- Chapter 4 - Programming exercixe 2
  2.                                        -- Chapter 4 - Program 2
  3. with Text_IO;
  4. use Text_IO;
  5.  
  6. procedure Ch04_2 is
  7.  
  8.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  9.    use Int_IO;
  10.  
  11.    package Enum_IO is new Text_IO.Enumeration_IO(BOOLEAN);
  12.    use Enum_IO;
  13.  
  14.    Index, Count           : INTEGER := 12;
  15.    Truth, Lies, Question  : BOOLEAN;
  16.  
  17. begin
  18.    Truth := Index = Count;      -- This is TRUE
  19.    Put("Truth now has the value of ");
  20.    Put(Truth);
  21.    New_Line;
  22.    Lies := Index < Index;       -- This is FALSE
  23.    Put("Lies now has the value of ");
  24.    Put(Lies);
  25.    New_Line;
  26.  
  27.                             -- Examples of all BOOLEAN operators
  28.    Question := Index =  Count;      -- Equality
  29.    Question := Index /= Count;      -- Inequality
  30.    Question := Index <  Count;      -- Less than
  31.    Question := Index <= Count;      -- Less than or equal
  32.    Question := Index >  Count;      -- Greater than
  33.    Question := Index >= Count;      -- Greater than or equal
  34.    Put("Question now has the value of ");
  35.    Put(Question);
  36.    New_Line;
  37.  
  38.                        -- Examples of composite BOOLEAN expressions
  39.    Question := Index = 12 and Count = 12 and Truth and TRUE;
  40.    Question := Index /= 12 or FALSE or Count > 3 or Truth;
  41.    Question := (Truth or Lies) and (Truth and not Lies);
  42.    Question := Truth xor Lies;
  43.    Put("Question now has the value of ");
  44.    Put(Question);
  45.    New_Line;
  46.  
  47.                        -- now for short circuit evaluation
  48.    Question := Index /= Count and then Index = 9/(Index - Count);
  49.    Question := Index = Count or else  Index = 9/(Index - Count);
  50.    Question := (Index = Count) or else (Index = 9/(Index - Count));
  51.    Put("Question now has the value of ");
  52.    Put(Question);
  53.    New_Line;
  54.  
  55. end Ch04_2;
  56.  
  57.  
  58.  
  59.  
  60. -- Result of execution
  61.  
  62. -- Truth now has the value of TRUE
  63. -- Lies now has the value of FALSE
  64. -- Question now has the value of TRUE
  65. -- Question now has the value of TRUE
  66. -- Question now has teh value of TRUE
  67.  
  68.  
  69.