C++ Morse Code

profileSeok123
MorseCodeConverter1.docx

Morse Code Converter

Morse code is a code where each letter of the English alphabet, each didit, and various punctuation characters are represented by a series of dots and dashes. There is a table in the book that shows part of the code.

Below is some C++ code that puts the code and alphabet into parallel arrays.

static int MORSESIZE = 40; // size of morse code table

// LETTERMATCH is a parallel array with MORSECODE for matching purposes

static char LETTERMATCH[40] = {' ',',','.','?','0','1','2','3','4','5','6','7','8','9','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'};

// [SP] , . ? 0 1 2 3 4 5

static string MORSECODE[40] = { " ","--..--",".-.-.-","..--..","-----",".----","..---","...--","....-",".....",

// 6 7 8 9 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

"--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};

You could copy this and drop it into your code if you choose.

Write a program that asks the user to enter a string, and then converts that string to Morse code.

Example