logo CodeStepByStep logo


Language/Type: C# Dictionary collections
Author: Eric Roberts (on 2019/07/08)

Write a method named ToMorseCode that converts strings into their Morse code equivalents. Morse code is a dictionaryping from each character from A-Z to a sequence of dots and dashes. For example, the string "SOS" could be represented in Morse code as "... --- ...".

Your method accepts two parameters: a SortedDictionary from char to string, and a string of text to convert. Assume that the provided client code builds a dictionary from individual text characters to their Morse code equivalents. For example, the key 'A' maps to ".-" . Your method accepts such a dictionary, and a string to be converted, and should print out the Morse code equivalent of the given string to the console.

For example, if the letter to Morse code dictionary is stored in a variable called mapping, the call of ToMorseCode(mapping, "SOS TITANIC"); should print the following console output:

... --- ... - .. - .- -. .. -.-.

Note that the string might contain some characters that are not uppercase A-Z letters (like spaces); just skip those characters. You may assume that the dictionaryping passed contains a dictionaryping for every letter from A-Z in uppercase. Do not modify the letter dictionary that is passed in.

Method: Write a C# method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.