Thread: morse code

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Atlanta
    Posts
    3
    Rep Power
    0

    morse code


    thanks for helpss. the thing is I just cant cheat because this is a homework for a class, and prof. clearly told that we should do it by using a function and arrays. So if you please explain it in details I would appriceate it.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    india
    Posts
    42
    Rep Power
    12

    morse code


    do u need the program which generates the morse code?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Atlanta
    Posts
    3
    Rep Power
    0
    yes but just a simple version of it.
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222

    Re: morse code


    Originally posted by mbaysan16
    thanks for helpss. the thing is I just cant cheat because this is a homework for a class, and prof. clearly told that we should do it by using a function and arrays. So if you please explain it in details I would appriceate it.
    Just because the link that was provided includes source code shouldn't mean that you cannot research it for ideas -- just so long as the code you end up writing is your own. Giving it due credit in the comments would be a nice idea. I don't think that would constitute cheating any more than posting here for help.

    Without having looked at that code, here are a few ideas that occur to me off the top of my head:

    1. Store the codes in an array.

    2. The codes are of varying lengths (eg, e = '.', a = '.-', s = '...'), so the data type for the codes needs to handle varying lengths, like strings.

    3. The ASCII code of the letter you are converting to morse will be used to index into the array. However, you must avoid empty entries in the array (eg, it cannot be a simple morse['A'] to get the code for 'A'). You will need to translate from the ASCII code to the corresponding index for the array. Also, you will need to handle mixed case; the ASCII code for an 'A' is different than for an 'a'.

    4. The function could either be the letter-to-index translation or, better, one that you pass the letter to and it returns the morse code.

    That should be more than enough to get you started.


    Of course, if you ever need to go from Morse back to ASCII, that would be a much more fun project. But definitely more advanced.
    Last edited by dwise1_aol; April 2nd, 2003 at 10:03 AM.
  8. #5
  9. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    Just a note: You should continue replying in the original thread so that others know what you are speaking about who have not read it, yet.

    Converting morse code back into ASCII would be a fun project... why didn't we do things like that in school? :)
  10. #6
  11. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    [i]Converting morse code back into ASCII would be a fun project... why didn't we do things like that in school? :) [/B]
    Actually we did, in a way. Upper division class on data communications back in 1981. Our programming assignments merged into a project which accepted an input text file, generated a Huffmann-code for it, Huffmann-encoded it into a bit stream, then decoded it back to the original text. We called it "Huff 'n Puff".

    Basically, Huffmann encoding is a simple form of data compression that uses character frequency to assign shorter bit strings for more frequent characters and the longer strings for the less frequent. Our instructor pointed out that Morse code does pretty much the same thing. A few years later, I read that Huffmann was an undergraduate student when he came up with it. His instructor presented to the class this problem he'd been working on and Huffmann came up with the approach that had been eluding the instructor. We learn from our students!

    The approach we were taught was to construct a binary tree and then start combining the nodes with the lower frequencies -- ie, connect them with an intermediate node whose frequency value is the sum of the nodes in its subtree. At first, we were to write a program to construct the tree, but too many students were having trouble with it so the instructor just had us do it by hand. Too late, I'd already written the program. I'll have to try to dig it out one of these days.

    Anyway, to decode, you read each bit coming in and use it to traverse down the tree. When you read a terminal node, print out that character, go back to the root of the tree, and continue on with the next input bit.

    I figure that a Morse code reader would be similar, except I think there are pauses between characters. Also, the code is already written, so you wouldn't have to generate the code.
    Last edited by dwise1_aol; April 2nd, 2003 at 08:28 PM.
  12. #7
  13. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    Yes, I did a bit of research on the Huffmann encoding algorithm. It is commonly used to compress chess positions to store in transpositional tables. I was looking to implement this into my small chess engine project for school, but I simply ran out of time. It still bothers me that I did not get this implemented, but I just have no time to mess with that stuff right now due to current (more important) projects. Huffman must have been quite an intelligent guy. I do not know why schools deter students from answering questions in their own way - I know that almost every class I took in school did so by marking questions incorrectly if they were not answered 'by the book'. I guess they do not realize that at some point in the past a 'student' wrote that book, and perhaps his method isn't the best way.
  14. #8
  15. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    I tend to suspect that the "by the book" instructors tend to be the ones who only know a bit more than the students do (not necessarily a bad thing -- when you are just starting out in a new subject, like foreign language and dancing, a teacher who still remembers being a beginner can be a lot better than one who knows it thoroughly and naturally) and therefore must depend on the book more.

    In Huffmann's case, the problem was one that the professor himself had been working on and was stumped. The professor kept wanting to start building the tree using he most frequent characters. Huffmann just took the opposite approach and started with the least frequent.

    Sometimes, genius is just looking at the same problem from a slightly different perspective.
  16. #9
  17. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    Originally posted by dwise1_aol
    Sometimes, genius is just looking at the same problem from a slightly different perspective.
    Yes, you are quite correct. It's part of of having an open mind, I guess. What you said reminds of this quote:

    "Open your mind up to things that have no connection with the problem you're trying to solve: subscribe to an unusual magazine; spend a morning at an elementary school; go to work two hours early; test drive an exotic car; attend a city council meeting; ...try an Indonesian recipe."
    - Roger von Oech

IMN logo majestic logo threadwatch logo seochat tools logo