September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,54 +1,29 @@
|
|||
with Ada.Text_IO, Ada.Containers.Ordered_Sets;
|
||||
with ada.containers.ordered_sets, ada.text_io;
|
||||
use ada.text_io;
|
||||
|
||||
procedure Set_Demo is
|
||||
procedure set_demo is
|
||||
package cs is new ada.containers.ordered_sets (character); use cs;
|
||||
|
||||
package CS is new Ada.Containers.Ordered_Sets(Character); use CS;
|
||||
package IO renames Ada.Text_IO;
|
||||
function "+" (s : string) return set is
|
||||
(if s = "" then empty_set else Union(+ s(s'first..s'last - 1), To_Set (s(s'last))));
|
||||
|
||||
-- helper functions for string to something conversion, and vice versa
|
||||
function To_Set(S: String) return Set is
|
||||
Result: Set;
|
||||
begin
|
||||
for I in S'Range loop
|
||||
begin
|
||||
Result.Insert(S(I));
|
||||
-- raises Constraint_Error if S(I) is already in Result
|
||||
exception
|
||||
when Constraint_Error => null;
|
||||
end;
|
||||
end loop;
|
||||
return Result;
|
||||
end To_Set;
|
||||
|
||||
function Image(S: Set) return String is
|
||||
C: Character;
|
||||
T: Set := S;
|
||||
begin
|
||||
if T.Is_Empty then
|
||||
return "";
|
||||
else
|
||||
C:= T.First_Element;
|
||||
T.Delete_First;
|
||||
return C & Image(T);
|
||||
end if;
|
||||
end Image;
|
||||
|
||||
function Image(C: Ada.Containers.Count_Type) return String renames
|
||||
Ada.Containers.Count_Type'Image;
|
||||
|
||||
S1, S2: Set;
|
||||
begin -- main program
|
||||
loop
|
||||
S1 := To_Set(Ada.Text_IO.Get_Line);
|
||||
exit when S1 = To_Set("quit!");
|
||||
S2 := To_Set(Ada.Text_IO.Get_Line);
|
||||
IO.Put_Line("Sets [" & Image(S1) & "], [" & Image(S2) & "] of size"
|
||||
& Image(S1.Length) & " and" & Image(S2.Length) & ".");
|
||||
IO.Put_Line("Intersection: [" & Image(Intersection(S1, S2)) & "],");
|
||||
IO.Put_Line("Union: [" & Image(Union(S1, S2)) & "],");
|
||||
IO.Put_Line("Difference: [" & Image(Difference(S1, S2)) & "],");
|
||||
IO.Put_Line("Symmetric Diff: [" & Image(S1 xor S2) & "],");
|
||||
IO.Put_Line("Subset: " & Boolean'Image(S1.Is_Subset(S2))
|
||||
& ", Equal: " & Boolean'Image(S1 = S2) & ".");
|
||||
end loop;
|
||||
end Set_Demo;
|
||||
function "-" (s : Set) return string is
|
||||
(if s = empty_set then "" else - (s - To_Set (s.last_element)) & s.last_element);
|
||||
s1, s2 : set;
|
||||
begin
|
||||
loop
|
||||
put ("s1= ");
|
||||
s1 := + get_line;
|
||||
exit when s1 = +"Quit!";
|
||||
put ("s2= ");
|
||||
s2 := + get_line;
|
||||
Put_Line("Sets [" & (-s1) & "], [" & (-s2) & "] of size"
|
||||
& S1.Length'img & " and" & s2.Length'img & ".");
|
||||
Put_Line("Intersection: [" & (-(Intersection(S1, S2))) & "],");
|
||||
Put_Line("Union: [" & (-(Union(s1, s2))) & "],");
|
||||
Put_Line("Difference: [" & (-(Difference(s1, s2))) & "],");
|
||||
Put_Line("Symmetric Diff: [" & (-(s1 xor s2)) & "],");
|
||||
Put_Line("Subset: " & Boolean'Image(s1.Is_Subset(s2))
|
||||
& ", Equal: " & Boolean'Image(s1 = s2) & ".");
|
||||
end loop;
|
||||
end set_demo;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue