1 -----------------------------------------------
  2 -- Programmer:  _Rory Bell
  3 -- Course:___CS 240
  4 -- Date Due: __9/25/07
  5 --_Language:__Ada
  6 -- Compiler used:_GNAT GPL
  7 -- Source Filename: __Discrete_Set.adb
  8 -- Executable Filename: None at the time
  9 -- Professor:__Adams
 10 -----------------------------------------------
 11 -----------------------------------------------
 12 -- Description
 13 -- Purpose:_To take Element Types and place them in to Set Types.
 15 -- Input:   An Element and a set to be placed in.
 16 -- Output:_The Set Types with Elements are being added, subtracted, 
      --                multiplied, compared to as greater than or less than, or equal to.
 17 -----------------------------------------------

ÏÕÖ×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); --return true if the element is in the set.
 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; --return a Set_Type from a left or right Set_Type.
14 ÏÏ§ÏÏ©end "+";
15 ÏÏ§

-- returns the value in the Left Set_Type as true at the given element.
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;		 -- Result is a Left Set_Type.
22 ÏÏ§ÏÏ¨¹¹ÏResult(Right) := True;   -- Add the new element to the set
23 ÏÏ§Â¹Ä¹¹Ïreturn Result;           
24 ÏÏ§ÏÏ©end "+";
25 ÏÏ§

-- returns the value in the Right Set_Type as true at the given element.
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;		-- Result is a Right Set_Type.
32 ÏÏ§ÏÏ¨¹¹ÏResult(Left) := True;   -- Add the new element to the set
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 both left and right.
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 the left but not the right.
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;
54 ÏÏ§ÏÏ¨¹¹ÏResult(Right) := False;   -- Remove the element from the set
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;
61 ÏÏ§ÏÏ§begin
62 ÏÏ§ÏÏ¨¹¹ÏIs_A_Subset := (Left - Right) = Empty_Set;
63 ÏÏ§Â¹Ä¹¹Ïreturn Is_A_Subset;  -- returns true when left value subtracted from 
64 ÏÏ§ÏÏ©end "<=";		   --  right value equals null.
65 ÏÏ§
66 ÏÏ§----------------------------------------------------------------------------
67 ÏÏ§ÏÞßàfunction "<" (Left : in Set_Type; Right : in Set_Type) return Boolean is
68 ÏÏ§ÏÏ§ÏíÏResult : Boolean;
69 ÏÏ§ÏÏ§begin
70 ÏÏ§ÏÏ¨¹³´if Left = Right then  -- If the sets are equal, not a proper subset
71 ÏÏ§ÏÏ§Ï6¾¹¹ÏResult := False;
72 ÏÏ§ÏÏ§Ïö´else
73 ÏÏ§ÏÏ§Ï¸¾¹¹ÏResult := Left <= Right;  -- If not equal, test for subset
74 ÏÏ§ÏÏ§ÏÈÏend if;                      -- using the function above
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
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
92 ÏÏ§ÏÏ©end ">";
93 ÏÏ§
94 ÏÏ©end Discrete_Set;
95