John F. Bergin               

Bellevue, WA

(425) 242-1394

 

John.F.Bergin@Comcast.net                            Resume

 

Word Formatted Resume (Right Click and "Save Target As")

 

Cover Letter                                                    White Papers                                            Code Examples

Senior Software Engineer                                                                                                                                                                                                          

Code Examples by John F. Bergin

 

    Print Missing Letters

    The following program prints the missing letters in a string of characters:

   

    // Print Missing Characters (lower case only)

    static String^ FindMissingLetters(String ^inArray)

    {

         // Input processing and Initialization

         String ^outArray = "Missing Letters:  \n";

         int  StoreResults = 0;

         int  length = inArray->Length;

         int ascii, index;

 

         // Find Missing Characters

         for ( index=0; index<length; index++)

         {   

           //Loop through lower case letters

           for ( ascii=97; ascii<=122; ascii++)

           {

                if ( inArray[index] == ascii )

                {

                     // Record that this letter has been found.

                     // Use 26 of the 32 bitts of StoreResults, "a" is LSB

                     StoreResults = StoreResults | ( (1<<(ascii-97)) );

                }

            }

         }

 

         // Store Missing Characters in String

         String ^letters = "abcdefghijklmnopqrstuvwxyz";

         for (int i=0;i<26;i++)

         {

           if ( ( (StoreResults >> i) & 0x01 ) == 0 )

           {

                outArray = outArray +  letters[i] + " " ;

           }

         }

 

         return outArray;

    };

 

    The following Test Window shows the results of a test of the "Print Missing Letters" program:

   

 

 

____________________________

Copyright © 2010 by John F. Bergin.

Home