1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
#include <cstring>
using namespace std;
string translate(string word)
{
string morseCode[] = {".-", "-...", "-.-.", "-..", ".", "..-.",
"--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---",
".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-",
"-.--", "--.."};
char ch;
string morseWord = "";
for(unsigned int i=0; i < word.length(); i++)
{
ch = word[i];
ch = toupper(ch);
morseWord += morseCode[ch - 'A'];
morseWord += " ";
}
return morseWord;
}
int main()
{
string sentence;
string word = "";
int currentLoc = 0; //Picks up after the last word
int index = 0; //Counter along the string
cout << "English: ";
getline(cin, sentence);
for(unsigned int i = 0; i < sentence.length(); i = currentLoc)
{
currentLoc = index;
for(unsigned int j = 0; j < sentence.find(" ", currentLoc); j++)
{
if(isalpha(sentence[j]))
word += sentence[j];
index++;
}
cout << word << endl;
word.clear();
}
}
|