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 == --....

1 answer below »

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',".-");


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];
}

Answered Same DayJul 24, 2021

Answer To: Write a program that given a sting as input converts it to morse code. Sample input: Enter word:sos...

Neha answered on Jul 25 2021
151 Votes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public cla
ss Program
{
private static Dictionary _morseAlphabetDictionary;
static void Main()
{
_morseAlphabetDictionary = new Dictionary()
{
{'a', ".-"},
{'b', "-..."},
{'c', "-.-."},
{'d', "-.."},
{'e', "."},
{'f', "..-."},
{'g', "--."},
{'h', "...."},
{'i', ".."},
{'j', ".---"},
{'k', "-.-"},
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here