Good day. My semester of c++ is coming to an end. I've got to complete a total of 7 assignments within the next 3 weeks. I've completed 5 out of the seven. I've got two left (1 has a separate thread by itself). So you can also take a look at it. This is the assignment:
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:
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.
This "extremely sophisticated" code has finally been broken by the professor and now the the students wants a code as follows:
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:
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;
Thanks for any ideas, jumpstart and help. Have a good day.