Write a program that given a sting as input converts it to morse code.
Sample input:
Enter word:sos
Sample output:
... --- ...
Alphabet:
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 == --..
Hints:
There are a few ways of achieving this. You might want to do this with 24 if-else statements, but that's going to drive you nuts. It's better to use, an appropriately named,dictionary. So, for this assignment it's declaration would look like:
Dictionary morseAlphabetDictionary = new Dictionary();
Then, simple add key-value pairs for each letter like so:morseAlphabetDictionary.Add('a',".-");
morseAlphabetDictionary.Add('a',".-");
After getting the user input, you can iterate through the word character-by-character using foreach loop:foreach (char c in text){morseText += morseAlphabetDictionary[c];}
foreach (char c in text){morseText += morseAlphabetDictionary[c];}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here