------------------------------------------------------------------
 -- Programmer : Murat Akhmetov
 -- Course : CS 240
 -- Due Date : September 26, 2007
 -- Language : ADA 95
 -- Professor : Elizabeth Adams
 -----------------------------------------------------------------
 1 ÏÕÖ×package body Discrete_Set is
 2 ÏÏ§
 3 ÏÏ§----------------------------------------------------------------------------
 4 ÏÏ§ÏÞßàfunction Is_Member (Set     : in Set_Type;  
 5 ÏÏ§ÏÏ§Ï                Element : in Element_Type) return Boolean is  
 6 ÏÏ§ÏÏ§begin
 7 ÏÏ§Â¹Ä¹¹Ïreturn Set(Element); -- returns the Boolean value under an element
     §  §                        -- of Set_Type array which corresponds to
     §  §                        -- Set(Element)
 8 ÏÏ§ÏÏ©end Is_Member;
 9 ÏÏ§
10 ÏÏ§----------------------------------------------------------------------------
11 ÏÏ§ÏÞßàfunction "+" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
12 ÏÏ§ÏÏ§begin
13 ÏÏ§Â¹Ä¹¹Ïreturn  Left or Right;-- returns a Set_Type containing all of the
     §  §                         -- elements which can be found in Left and Right
14 ÏÏ§ÏÏ©end "+";
15 ÏÏ§
16 ÏÏ§----------------------------------------------------------------------------
17 ÏÏ§ÏÞßàfunction "+" (Left  : in Set_Type; 
18 ÏÏ§ÏÏ§Ï          Right : in Element_Type) return Set_Type is
19 ÏÏ§ÏÏ§ÏíÏResult : Set_Type;
20 ÏÏ§ÏÏ§begin
21 ÏÏ§ÏÏ¨¹¹ÏResult := Left; -- assigns the Set_Type Left to Result
22 ÏÏ§ÏÏ¨¹¹ÏResult(Right) := True;  -- Add the new element to the set by switching
     §  §                           -- the Boolean value in Result(Right) to true
23 ÏÏ§Â¹Ä¹¹Ïreturn Result;
24 ÏÏ§ÏÏ©end "+";
25 ÏÏ§
26 ÏÏ§----------------------------------------------------------------------------
27 ÏÏ§ÏÞßàfunction "+" (Left  : in Element_Type;
28 ÏÏ§ÏÏ§Ï          Right : in Set_Type) return Set_Type is
29 ÏÏ§ÏÏ§ÏíÏResult : Set_Type;
30 ÏÏ§ÏÏ§begin
31 ÏÏ§ÏÏ¨¹¹ÏResult := Right; -- assigns the Set_Type Right to Result
32 ÏÏ§ÏÏ¨¹¹ÏResult(Left) := True;  -- Add the new element to the set by switching
     §  §                          -- the Boolean value in Result(Left) to true
33 ÏÏ§Â¹Ä¹¹Ïreturn Result;
34 ÏÏ§ÏÏ©end "+";
35 ÏÏ§
36 ÏÏ§----------------------------------------------------------------------------
37 ÏÏ§ÏÞßàfunction "*" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
38 ÏÏ§ÏÏ§begin
39 ÏÏ§Â¹Ä¹¹Ïreturn  Left and Right;-- returns a Set_Type containing all of the
     §  §                         -- common elements of Left and Right sets
40 ÏÏ§ÏÏ©end "*";
41 ÏÏ§
42 ÏÏ§----------------------------------------------------------------------------
43 ÏÏ§ÏÞßàfunction "-" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
44 ÏÏ§ÏÏ§begin
45 ÏÏ§Â¹Ä¹¹Ïreturn Left and not Right; -- returns a Set_Type containing elements
     §  §                          -- which are in Left set but not in Right set
46 ÏÏ§ÏÏ©end "-";
47 ÏÏ§
48 ÏÏ§----------------------------------------------------------------------------

49 ÏÏ§ÏÞßàfunction "-" (Left  : in Set_Type;
50 ÏÏ§ÏÏ§Ï          Right : in Element_Type) return Set_Type is
51 ÏÏ§ÏÏ§ÏíÏResult : Set_Type;
52 ÏÏ§ÏÏ§begin
53 ÏÏ§ÏÏ¨¹¹ÏResult := Left; -- assigns the Set_Type Left to Result
54 ÏÏ§ÏÏ¨¹¹ÏResult(Right) := False; -- Remove the element from the set by switching
     §  §                           -- the Boolean value in Result(Right) to false
55 ÏÏ§Â¹Ä¹¹Ïreturn Result;
56 ÏÏ§ÏÏ©end "-";
57 ÏÏ§
58 ÏÏ§----------------------------------------------------------------------------
59 ÏÏ§ÏÞßàfunction "<=" (Left : in Set_Type; Right : in Set_Type) return Boolean is
60 ÏÏ§ÏÏ§ÏíÏIs_A_Subset : Boolean;-- indicates if the Set_Type Left is the subset
     §  §                         -- of the Set_Type Right
61 ÏÏ§ÏÏ§begin
     §  §   -- Checks whether Left set is a subset of Right set:
     §  §   -- if the difference of 2 sets is empty set, that is if all elements
     §  §   -- in Set_Type Left are in Set_Type Right, then Left is a subset of
     §  §   -- Right (Is_A_Subset = true); otherwise Is_A_Subset = false.
62 ÏÏ§ÏÏ¨¹¹ÏIs_A_Subset := (Left - Right) = Empty_Set;
63 ÏÏ§Â¹Ä¹¹Ïreturn Is_A_Subset;
64 ÏÏ§ÏÏ©end "<=";
65 ÏÏ§
66 ÏÏ§----------------------------------------------------------------------------
67 ÏÏ§ÏÞßàfunction "<" (Left : in Set_Type; Right : in Set_Type) return Boolean is
68 ÏÏ§ÏÏ§ÏíÏResult : Boolean;
69 ÏÏ§ÏÏ§begin
     §  §   -- Checks whether Left set is a proper subset of Right set:
70 ÏÏ§ÏÏ¨¹³´if Left = Right then  -- If the sets are equal, not a proper subset
     §  §  §                      -- because to be a proper subset there must be at
     §  §  §                      -- least one element in Right which is not in Left
71 ÏÏ§ÏÏ§Ï6¾¹¹ÏResult := False;
72 ÏÏ§ÏÏ§Ïö´else
73 ÏÏ§ÏÏ§Ï¸¾¹¹ÏResult := Left <= Right;  -- If not equal, test for subset
74 ÏÏ§ÏÏ§ÏÈÏend if;                      -- using the previous function: if there
     §  §                                -- is at least one element in Left which is
     §  §                                -- not in Right, then Left is not a proper
     §  §                                -- subset of Right (Result = false).
75 ÏÏ§Â¹Ä¹¹Ïreturn Result;
76 ÏÏ§ÏÏ©end "<";
77 ÏÏ§
78 ÏÏ§----------------------------------------------------------------------------
79 ÏÏ§ÏÞßàfunction ">=" (Left : in Set_Type; Right : in Set_Type) return Boolean is
80 ÏÏ§ÏÏ§begin
81 ÏÏ§Â¹Ä¹¹Ïreturn  Right <= Left;   -- Reverse the order of the 
82 ÏÏ§ÏÏ§                         -- parameters and use the operation 
83 ÏÏ§ÏÏ§                         -- we've already written, that is checks
     §  §                         -- whether Right set is a subset of Left set.
84 ÏÏ§ÏÏ©end ">=";
85 ÏÏ§
86 ÏÏ§----------------------------------------------------------------------------
87 ÏÏ§ÏÞßàfunction ">" (Left : in Set_Type; Right : in Set_Type) return Boolean is
88 ÏÏ§ÏÏ§begin
89 ÏÏ§Â¹Ä¹¹Ïreturn  Right < Left; -- Reverse the order of the 
90 ÏÏ§ÏÏ§                         -- parameters and use the operation 
91 ÏÏ§ÏÏ§                         -- we've already written, that is checks whether
     §  §                         -- Right set is a proper subset of Left set.
92 ÏÏ§ÏÏ©end ">";
93 ÏÏ§
94 ÏÏ©end Discrete_Set;
95