The morseCodeTree class is implemented using the Trie data structure, which functions identically to a Deterministic Finite Automaton (DFA). The root of the tree is the starting state, and each node in the morseCodeTree (or state, in DFA terms), contains a letter and transition(s) to other nodes.
When given morse code (e.g.: ..-) to translate, the morseCodeTree will start from its root and recursively traverse through the tree based on the current character (. or -) it is reading while reading each character in the code from left to right. Once the morse code is read, if the morse code is a valid sequence of characters that can be translated to a letter, the current node or state will contain the letter (e.g.: u) that corresponds to the given morse code. Invalid morse codes will lead to a state that contains the null character '\0'.
The morseCodeTree instance is created at the beginning of program execution, and all valid morse code sequences are added to the tree through a hard-coded array of size 26 that contains the morse code sequences for all 26 letters in the English alphabet.
- Clone the repo.
- Compile .cpp files and create an executable file through the terminal app with command
g++ *.cpp -o morseCode.exe -Wall. - Files should successfully compile without errors or warnings.
- Run the executable with the input file as a command line argument through the teriminal app with command
./morseCode.exe sampleInput.txt. - Program should translate the morse code from 'sampleInput.txt' file and output the translation on the console of the terminal app.
Morse code is a way to encode messages in a series of long and short sounds or visual signals. During transmission, operators use pauses to split letters and words.
Please write a program which will translate lines of Morse code into readable English text. The program should:
- Accept a flat file as input.
- Each new line will contain a string of Morse code. The characters used will be:
- . = dot
- - = dash
- || = break
- Output the English text for each line
-..||---||--.
….||.||.-..||.-..||---||||.--||---||.-.||.-..||-..
dog
hello world