Can anyone give some help plz? the instructor said no strings, array can be used. just use simple concepts however dont have any idea at all. its killing me...
Q4: [Morse Code] (10%)
The figure below shows the mapping between alphabetic character and moose code. Each letter in the alphabet corresponds to a sequence of dots and slashes. For example, in order to write out “SOS”, the sequence of dot and slash is as follows: “... --- ...”. Such a sequence is called the Morse Code (https://en.wikipedia.org/wiki/Morse_code).
Write a program to convert an inputted Morse code back to the alphabetic characters. For the SOS example, the input will be “...|---|...!” where the stroke letter (‘|’) is to separate the characters to be decoded, and the letter ‘!’ denotes the end of the Morse code.
Hint: consider using user-defined function to make your code shorter. Note that the use of function is optional.
Samples inputs and outputs are given below.
Example 1
Input morse code: ...|---|...!
Output message: SOS
What were the topics of your two most recent lectures and how well did you understand them? Just to know in what direction they would like to have the solution and where you need the help.
Python could do this very easily I think. Break up the string you get as an input and then just treat each piece seperately, finding all the characters based on the split string and then return that
This is a brilliant assignment as there are many ways that you could do it.
Somewhere, you will have to have arrays (probably, unless you are going to use bits) to store the morse-code character representations ( dots and dashes, 0 and 1, ... take your pick).
You will have to input your sequence in some way: not specified, may be up to you. Could be a single long message or character by character.
Scan along your sequence, stopping at every divider (|) and comparing your most recent morse character with your stored arrays.
If you are developing the code (as opposed to the dire method of trying to write the whole thing first and then debug it) I suggest:
- first, input a definite dot-dash sequence and compare against your stored arrays (isolated task - a function, maybe?)
- then get it to read from the input as far as the first divider and do the same;
- finally, get a multi-character, arbitrary-length input to work.
Because there are so many strategies for doing this in code, follow integralfx's suggestion and show us what you have tried. But definitely break it up into stages - don't try to complete the whole thing in one go.