C++ Program - CODE TRANSLATOR
You have been hired you to write a special code translating program. They usually use a simple letter transformation, where the alphabets sequence of letters is started at somewhere other than the letter "A".
Example:
Expand|Select|Wrap|Line Numbers
- H I J K L M N O P Q R S T U V W X Y Z A B C D E F G
- A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
- Where H = A. R = K. A=T. G=Z.
1. Enter a key phrase ( no spaces)
2. Remove all the duplicate letters in the key phrase.
3. Remove the letters that remain in the edited key phrase from the string of the 26 alphabet letters.
4. Connect the edited key phrase to the front of the edited alphabet.
5. Use this new string to transform letters in the code to the alphabet (similar to the above example)
Example:
1. Key Phrase: DOCTORZOOSSCIENCEREVIEWS
2. Remove duplicates: DOCTRZSIENVW
3. Remove these letters from the alphabet: ABFGHJKLMPQUXY
4. Connect these two: DOCTRZSIENVWABFGHJKLMPQUXY
5. Use to decode; ABCDEFGHIJKLMNOPQRSTUMXYZ
CODE : CDMLEFB LIR AFMBLDEBK DJR ZMWW FZ IEWWK
TRANSL : CAUTION THE MOUNTAINS ARE FULL OF HILLS
Write a program called "DECODE" that will allow for the keyboard entry of the key phrase (which Mr. Brown will supply to you), read one line of code from a text file, decode it and display the translation to the screen and printer. The
text files are individual and named as follows:
c:\\f(9999).txt example: f1234.txt
Here is one way of removing duplicates from a string;
1. Enter string1 and set string2 equal to a null string.
2. Set up a nested for loop. Loop1 from 0 to 1 less than the string1 length. Loop2 from Loop1 + 1 to 1 less than the string1 length (same as the Bubble Sort loops)
3. If the letters pointed to by both loops are equal, set the Loop2 letter to an *
4. After the loops are finished, start another loop from 0 to length of string1
5. If the letter is NOT an *, then concatenate it to the end of string2.
Here's an idea:
Expand|Select|Wrap|Line Numbers
- string stringl, string2;
- string2 = “ “ // making string2 a null string
- cout << "Enter string1; ";
- getline(cin, string1);
- for(i=0; I < string1.Iength()-1; i++)
- for(j=i+1; ]< string1.length();j++)
- {
- if(string1[i] ! =’ ‘ ) // skipping spaces
- {
- if (string1[i] == string1 [j]) // finding duplicates
- string1[j] = ‘*’; // making the duplicate letter a '*'
- )// end if
- ) // end for j
- // Removing the *'s, spaces and creating a new string
- for(i=0; i < string1.length(); i++)
- {
- if(string1[i] != '*' && stringi [i] != ' ') // checking for an asterick (*) and a space
- string2 += string1[i];
- } // end for i
- cout <<string2 << endl;