Using switch case for morse code decoder

Astric

New member
Joined
Apr 11, 2020
Messages
1
Programming Experience
Beginner
Hi,

how can I use this code win C# Console application. I am total greenhorn in writeing apps.

I need to create app that converts alphabet to morse code.



In class we use visual studio 2015. We are crating app in C# console applications for windows.



Our apps templates starts with:

C#:
       using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication4
    {
        class Program
        {
            static void Main(string[] args)
            {
            }
        }
    }





Program I found on Morse Code Implementation - GeeksforGeeks

Is:

C#:
    // C# program to demonstrate Morse code

using System;

 

class GFG

{

    // function to encode a alphabet as

    // Morse code

    static string morseEncode(char x) 

    {

     

        // refer to the Morse table

        // image attached in the article

        switch (x) 

        {

            case 'a':

                return ".-";

            case 'b':

                return "-...";

            case 'c':

                return "-.-.";

            case 'd':

                return "-..";

            case 'e':

                return ".";

            case 'f':

                return "..-.";

            case 'g':

                return "--.";

            case 'h':

                return "....";

            case 'i':

                return "..";

            case 'j':

                return ".---";

            case 'k':

                return "-.-";

            case 'l':

                return ".-..";

            case 'm':

                return "--";

            case 'n':

                return "-.";

            case 'o':

                return "---";

            case 'p':

                return ".--.";

            case 'q':

                return "--.-";

            case 'r':

                return ".-.";

            case 's':

                return "...";

            case 't':

                return "-";

            case 'u':

                return "..-";

            case 'v':

                return "...-";

            case 'w':

                return ".--";

            case 'x':

                return "-..-";

            case 'y':

                return "-.--";

            // for space

            case 'z':

                return "--..";

        }

        return "";

    }

     

    static void morseCode(string s) 

    {

        // character by character print 

        // Morse code

        for (int i = 0;i<s.Length; i++)

            Console.Write(morseEncode(s[i]));

            Console.WriteLine();

    }

     

    // Driver code 

    public static void Main ()

    {

        string s = "geeksforgeeks";

        morseCode(s);

    }

}

 

// This code is contributed by vt_m.



My question is:

How can I implement this code to work with my tamplate. I need to create app tahat is useing switch case for convert alphabet to morse.



Thanks and have a nice day.
 
In general, you should learn to write your own code instead of taking someone else's code and trying to adapt it. This is particularly important if you are still learning to write code.

Anyway, the template that you are starting with in the your first chunk of code is the Visual Studio default. You've not even put any effort at all at trying to create an app. Do you even know how the Main() method works? If so, then check out the code that you stole from GeekForGeeks and see how they are using their Main().
 
We only spoke about this the other night Skydiver. Why trying to learn to code by using someone else's work is one of the crappiest ways to learn to code. Not only will you not develop your own style, but you will adapt the style of the person's work you just stole.

You also adapt their horrible habits, and writing techniques; none of which will be unique to yourself, and you are more likely to fail as a programmer, mostly by been misguided by whoever's code you used, and the mistakes they probably made. Programmers develop their own writing concepts, and those concepts may contain bugs, vulnerabilities, and often just poorly written examples. I'm very sceptical about recommending books and links as sources to learn from. But you won't go wrong by following the Getting Started tutorial in my signature by Microsoft.

What makes a good programmer, is someone who learned the language through actual study, courses, and collage work, and someone who develops their own personal style over time and with experience. Someone who writes their own code from scratch. If you're unable to do that. Then it's a safe guess to suggest you're probably learning a language which doesn't interest you.
 

Latest posts

Back
Top Bottom