Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Write a simple \"translator\" program using a map where the keys are English

ID: 3535697 • Letter: C

Question

C++

Write a simple "translator" program using a map where the keys are English words and the values are corresponding words in another language. (Pick a language you know, if possible. Otherwise, pick whatever you want and look up some vocabulary for it.) Include at least 10 words. The way it should work is: Ask the user to enter a complete sentence. Break the sentence into words. For each word, figure out if there is a translation available in your map. If there is, replace the word with its translation. If not, leave the original English word alone, Print out the final translated version of the sentence.

Explanation / Answer

#include <iostream>

#include <string>


using namespace std;


int main ()

{

ios_base::sync_with_stdio (0);

const string alpha [27] = {"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"," "};

const string l337 [27] = {"λ","]3","(","|)","€","|=","(_>","|-|","!","_|","|<","|_","|V|","|V","0","|>","0_","|2","$","~|~","|_|","V","uJ","><"," ¥","z"," "};

string input;

string output;

int index;

int i;

getline (cin, input);

for (i = 0; i < input.size (); i ++)

{

if (input [i] > 96)

input [i] -= 32;

if (input [i] != ' ')

index = int (input [i] - 65);

else

index = 26;

output += l337 [index];

}

cout<<output<<endl;

return 0;

}



If input is :- Hello

Output is :|-|€|_|_0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote