Question

Program Description: A C# app is to be created to produce Morse code. The Morse code...

Program Description: A C# app is to be created to produce Morse code. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. In a sound-oriented system, a space is indicated by a short period of time during which no sound is transmitted. The international version of the Morse code is stored in the data file Morse.txt.

To process the program, the Morse code data file (Morse.txt) should be read and stored in memory for fast access to the code. Each letter of the alphabet has a Morse code equivalent. After the code table is stored, the user should be prompted for an English language phrase to be entered from the keyboard. This phrase should be encoded into Morse and displayed. One blank should be used to separate each Morse-coded letter and three blanks should be used to separate each Morse-coded word. The user should be allowed to continue with the process of entering a phrase and having it encoded until a sentinel value (0) is received.

Input: The letters and their equivalents are stored in a data file named Morse.txt. Input will consist of the Morse.txt file and well as the sentences entered from the keyboard. The data file should be read and loaded into memory at the beginning of the program before the sentences can be read and encoded. Each line of the data file contains the letter of the alphabet followed by the code equivalent. The data file should be read and stored as a collection in memory for fast and easy access during the program duration. When a sentence is read from the keyboard, it can be translated from the data stored from the Morse code file. The type of collection that can be used to store the Morse code file may be arrays.

Sample of Morse.txt:

A .-

B -...

C -.-.

D -..

E.

.

.

.
Z --..

Output: Output will consist of the display of the original sentence and it Morse code equivalent.

Requirements:

Required name for the main program: Morse.cs

You will need to write a separate user-defined class for this program. Please name that Code.cs

Hints:

In the beginning of the program, read the Morse.txt file and store the data items in parallel ArrayList objects (String data type will be the easiest to work with; however you can use Character if you wish).

After the file is read and loaded into memory, the user can begin to enter the sentences to be coded.

Continue to process until the user has finished entering sentences.

Information on the ArrayList class can be found in the Topic 5 C# Collection Classes

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Copyable code:

File Name: Code.cs

using System;

using System.IO;

using System.Collections;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

//Create name space

namespace App16

{

//Create class

class Code

{

//Create list

static ArrayList a1;

static ArrayList a2;

//Create constructor

public void ReadFromFile()

{

string lne;

string sep = "\t";

a1 = new ArrayList();

a2 = new ArrayList();

try

{

// Read the file and display it line by line.

StreamReader fle = new StreamReader(@"C:\Users\301624\Documents\Visual Studio 2012\Projects\ConsoleApplication17\ConsoleApplication17\Morse.txt");

while ((lne = fle.ReadLine()) != null)

{

string[] wrd = lne.Split(sep.ToCharArray());

a1.Add((char)wrd[0].ElementAt(0));

a2.Add(wrd[1]);

}

fle.Close();

}

catch (FileNotFoundException xp)

{

}

}

//Define function

public void GetStringFromUser()

{

while (true)

{

Console.WriteLine("Enter a string to convert:");

string inp1 = Console.ReadLine();

inp1 = inp1.ToUpper();

if (inp1 == "0")

break;

FunTranslate(inp1);

}

}

//Define function

private static void FunTranslate(string inp1)

{

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

int fg = 0;

foreach (char character in input)

{

fg = 0;

if (character == ' ')

{

fg = 1;

sb.Append(" ");

}

else

{

for (int kk = 0; kk < a1.Count; kk++)

{

if ((char)a1[kk] == character)

{

fg = 1;

sb.Append(a2[kk]);

sb.Append(" ");

}

}

if (fg != 1)

{

sb.Append(character);

sb.Append(" ");

}

}

}

Console.WriteLine("Converted: {0}", sb.ToString());

}

}

}

File Name: Morse.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

//Create namespace

namespace App17

{

//Create class

class Morse

{

//define function

static void Main(string[] args)

{

//Create object

Code mycode = new Code();

//Call function

mycode.ReadFromFile();

//Call function

mycode.GetStringFromUser();

//Pause window

Console.ReadLine();

}

}

}

Add a comment
Know the answer?
Add Answer to:
Program Description: A C# app is to be created to produce Morse code. The Morse code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program Description: A Java program is to be created to produce Morse code. The Morse code...

    Program Description: A Java program is to be created to produce Morse code. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. In a sound-oriented...

  • msp430 launchpad 2553 C programming Write a program for the microcontroller that flashes the Morse code pattern of a string. The Morse code is a system used to transmit characters and numbers through...

    msp430 launchpad 2553 C programming Write a program for the microcontroller that flashes the Morse code pattern of a string. The Morse code is a system used to transmit characters and numbers through light or sound signals. Each character is mapped to a series of ‘dots’ and ‘dashes’ as shown below. For example, the letter A is (dot-dash), the letter B is (dash-dot-dot-dot) etc. To show a Morse letter on the microcontroller, the LED blinks for a short duration to...

  • Help with writing morse code

    Screen Shot 2021-03-17 at 9.57.42 AM.pngScreen Shot 2021-03-17 at 9.57.49 AM.png3 Decoding a Morse Code messageIn this exercise you will decipher a Morse code message sent to Agent 008 by Agent \(007 .\) The last words of Agent 007 were "The future of technology lies in \(\ldots\) " at which point she produced a memory stick containing a MATLAB file ctftmod.mat. The file ctftmod \(.\) mat contains the following:af, bf the denominator and numerator coefficients of a lowpass filter, whose...

  • Help write down below program with C++ language!!! Please... The Cipher Program Requirements An interactive program...

    Help write down below program with C++ language!!! Please... The Cipher Program Requirements An interactive program is required that allows a user to encode text using any of three possible ciphers. The three ciphers you are to offer are: Caesar, Playfair and Columnar Transposition. • The program needs to loop, repeating to ask the user if they wish to play with Caesar, Playfair or Columnar Transposition until the user wishes to stop the program. •For encoding, the program needs to...

  • JAVA Code: Complete the program that reads from a text file and counts the occurrence of...

    JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...

  • ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of...

    ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of a file. The program encoded sentences in the file and writes the encoded sentences to the output file. Enter the file name: messages.txt Output: encoded words are written to file: messages.txt.swt The program reads the content of the file and encodes a sentence by switching every alphabetical letter (lower case or upper case) with alphabetical position i, with the letter with alphabetical position 25...

  • The Morese code was developed by Alfred Vail while he is working in 1830 with Samuel...

    The Morese code was developed by Alfred Vail while he is working in 1830 with Samuel Morse in the invention of electric telegraph . Vail created a method by which each letter or number was transmitted individually with a consistent code stripes Y points , Ie telegraphic signals that differ in the duration of the active signal. Morse recognized the suitability of this system and he patented together with the electric telegraph. It was known as American Morse Code and...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • THE ATTACHMENTS:( needed to solve the problem above) (1) My Morse Code Program: #03/22/2018 #Creating a...

    THE ATTACHMENTS:( needed to solve the problem above) (1) My Morse Code Program: #03/22/2018 #Creating a program that translates sentences in to morse code def main():    morsecode_dict={}    line=""   f1 = open("MorseCode.txt",'r');    content = f1.readlines()    for x in content: #print x x=x.split() my_dict[x[0]]=x[1] print (morsecode_dict)    val=raw_input("Enter a String value: ") val.upper() output=""    for i in val: print (i.upper()) if(i!=' '): output = output + morsecode_dict[i.upper()]+' ' else: output = output+'\n' print ("-----Morse Code of The...

  • Java Programming Language Edit and modify from the given code Perform the exact same logic, except...

    Java Programming Language Edit and modify from the given code Perform the exact same logic, except . . . The numeric ranges and corresponding letter grade will be stored in a file. Need error checking for: Being able to open the text file. The data makes sense: 1 text line of data would be 100 = A. Read in all of the numeric grades and letter grades and stored them into an array or arraylist. Then do the same logic....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT