Example #1
0
 // constructor that performs a deep copy of another LetterSet object
 public LetterSet(LetterSet LetterSetWeWantToCopy)
 {
     letterIsSet = (LetterSetWeWantToCopy.Copy()).letterIsSet;
 }
Example #2
0
        // method Intersect
        public LetterSet Intersect(LetterSet that)
        {
            LetterSet theOther = new LetterSet();

            for (int i = 0; i < totalNumberOfPossibleLetters; i++)
            {
                if (this.letterIsSet[i] && that.letterIsSet[i])
                {
                    theOther.letterIsSet[i] = true;
                } // end if
            } // end for loop

            return theOther;
        }
Example #3
0
        // LetterSet Tester
        static void Main(string[] args)
        {
            LetterSet test1 = new LetterSet();
            LetterSet test2 = new LetterSet("God said let there be light!");
            LetterSet test3 = new LetterSet();
            LetterSet test4 = new LetterSet(test2);
            LetterSet test5 = new LetterSet("abcdefghijklmnop");
            LetterSet test6 = new LetterSet("hijklmnopqrstuv");
            LetterSet test7 = new LetterSet("qrstuvwxyz");
            LetterSet test8 = new LetterSet(test5);

            Console.WriteLine(test1);
            Console.WriteLine(test2);
            Console.WriteLine(test3);
            Console.WriteLine(test4);
            Console.WriteLine("");

            test1.Insert("Z");
            test2.Insert("z");

            Console.WriteLine(test1);
            Console.WriteLine(test2);
            Console.WriteLine(test3);
            Console.WriteLine(test4);
            Console.WriteLine("");

            test1.Remove("rz");
            test2.Remove("rZ");

            Console.WriteLine(test1);
            Console.WriteLine(test2);
            Console.WriteLine(test3);
            Console.WriteLine(test4);
            Console.WriteLine("");

            test1 = test2.Copy();
            test3 = test2.Copy();

            Console.WriteLine(test1);
            Console.WriteLine(test2);
            Console.WriteLine(test3);
            Console.WriteLine(test4);
            Console.WriteLine("");

            Console.WriteLine("\nNow we shall test the unions and intersections!\n\nIntersect 5 and 6:");
            Console.WriteLine(test5.Intersect(test6));
            Console.WriteLine("\nIntersect 6 and 7");
            Console.WriteLine(test6.Intersect(test7));
            test5 = test8.Union(test6).Union(test7);
            Console.WriteLine("\nUnion 6, 7, and 8; store value in 5 and make sure 8 did not change:");
            Console.WriteLine(test5);
            Console.WriteLine(test8);
            Console.WriteLine("");
        }