Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Morse Code Converter Design a program that asks the user to enter a string and t

ID: 3713140 • Letter: M

Question

Morse Code Converter Design a program that asks the user to enter a string and then converts that string to Morse code. Morse code is a code where each letter of the English alphabet, each digit, and various punctuation characters are represented by a series of dots and dashes . Table 8-7shows part of the code. Table 8-7 Morse code Character Code Character Code Character Code Character Code space space 6 -.... G --. Q --.- comma --..-- 7 --... H .... R .-. period .-.-.- 8 ---.. I .. S … ? ..--.. 9 ----. J .--- T - 0 ----- A .- K -.- U ..- 1 .---- B -... L .-.. V ...- 2 ..--- C -.-. M - -- W .-- 3 ...-- D -.. N -. X -..- 4 ....- E . O --- Y -.-- 5 ..... F ..-. P .--. Z --..

Programming language- C# Visual Basic

Here is my code:

private void convertButton_Click(object sender, EventArgs e)
{
{
Dictionary<char, String> morseCode = new Dictionary<char, String>()
{

{'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' , "--.."},

{'0' , "-----"},{'1' , ".----"},{'2' , "..----"},{'3' , "...--"},
{'4' , "....-"},{'5' , "....."},{'6' , "-...."},{'7' , "--..."},
{'8' , "---.."},{'9' , "----."},{'?' , "..--.."},{'.' , ".-.-.-"},
{' ' , " " }, {',' , "--..--"}


};
string wordOrPhrase = convertInputTextBox.Text;
wordOrPhrase = convertInputTextBox.ToString();
//string codeConvert = string.Empty;
char Letter_number;
foreach (char ch in wordOrPhrase)
{
// char.ToUpper(ch);
//Letter_number = char.ToUpper(ch);
if (wordOrPhrase.ContainsKey(morseCode))
{
morseCodeOutputLabel.Text += morseCode[Letter_number];

}
}
}
}

My issue: Everything seems correct with the dictionary and the input, but I can't seem to get the logic down. I am trying to have the user input a phrase or word then have the label output the morse code as a phrase or a word.

Explanation / Answer

Here is fixed logic

System.Text.StringBuilder sb = new System.Text.StringBuilder();

foreach (char ch in wordOrPhrase)

{

// char.ToUpper(ch);

//Letter_number = char.ToUpper(ch);

if (morseCode.ContainsKey(ch))

{

sb.append(morseCode[ch]);

}

else

{

sb.Append(ch);

}

}

morseCodeOutputLabel.Text = sb.ToString();

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote