Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 Day Jul 24, 2021

Solution

Neha answered on Jul 25 2021
138 Votes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class 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