logo CodeStepByStep logo


Language/Type: C++ Map collections
Related Links:
Author: Eric Roberts and Marty Stepp (on 2016/06/16)

Write a function named toMorseCode that converts strings into their Morse code equivalents. Morse code is a mapping 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 function accepts two parameters: a reference to a Map from char to string, and a string of text to convert. Assume that the provided client code builds a map from individual text characters to their Morse code equivalents. For example, the key 'A' maps to ".-" . Your function accepts such a map, 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 map 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 mapping passed contains a mapping for every letter from A-Z in uppercase. Do not modify the letter map that is passed in.

Type your C++ solution code here:

This is a function problem. Write a C++ function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.