Computer Science Canada Morse Code Translator |
Author: | WD_40 [ Thu Nov 29, 2007 1:21 pm ] |
Post subject: | Morse Code Translator |
%Bill Daniels %November 29, 2007 %Morse Code %Translates Entered Word Or Phrase Into Morse Code var strWord : string put "Enter a word or phrase" get strWord : * for i : 1 .. length (strWord) if strWord (i) = "a" then put ".-" .. elsif strWord (i) = "b" then put "-..." .. elsif strWord (i) = "c" then put "-.-." .. elsif strWord (i) = "d" then put "-.." .. elsif strWord (i) = "e" then put "." .. elsif strWord (i) = "f" then put "..-." .. elsif strWord (i) = "g" then put "--." .. elsif strWord (i) = "h" then put "...." .. elsif strWord (i) = "i" then put ".." .. elsif strWord (i) = "j" then put ".---" .. elsif strWord (i) = "k" then put "-.-" .. elsif strWord (i) = "l" then put ".-.." .. elsif strWord (i) = "m" then put "--" .. elsif strWord (i) = "n" then put "-." .. elsif strWord (i) = "o" then put "---" .. elsif strWord (i) = "p" then put ".- -." .. elsif strWord (i) = "q" then put "--.-" .. elsif strWord (i) = "r" then put ".-." .. elsif strWord (i) = "s" then put "..." .. elsif strWord (i) = "t" then put "-" .. elsif strWord (i) = "u" then put "..-" .. elsif strWord (i) = "v" then put "...-" .. elsif strWord (i) = "w" then put ".--" .. elsif strWord (i) = "x" then put "-..-" .. elsif strWord (i) = "y" then put "-.--" .. elsif strWord (i) = "z" then put "--.." .. elsif strWord (i) = "A" then put ".-" .. elsif strWord (i) = "B" then put "-..." .. elsif strWord (i) = "C" then put "-.-." .. elsif strWord (i) = "D" then put "-.." .. elsif strWord (i) = "E" then put "." .. elsif strWord (i) = "F" then put "..-." .. elsif strWord (i) = "G" then put "--." .. elsif strWord (i) = "H" then put "...." .. elsif strWord (i) = "I" then put ".." .. elsif strWord (i) = "J" then put ".---" .. elsif strWord (i) = "K" then put "-.-" .. elsif strWord (i) = "L" then put ".-.." .. elsif strWord (i) = "M" then put "--" .. elsif strWord (i) = "N" then put "-." .. elsif strWord (i) = "O" then put "---" .. elsif strWord (i) = "P" then put ".--." .. elsif strWord (i) = "Q" then put "--.-" .. elsif strWord (i) = "R" then put ".-." .. elsif strWord (i) = "S" then put "..." .. elsif strWord (i) = "T" then put "-" .. elsif strWord (i) = "U" then put "..-" .. elsif strWord (i) = "V" then put "...-" .. elsif strWord (i) = "W" then put ".--" .. elsif strWord (i) = "X" then put "-..-" .. elsif strWord (i) = "Y" then put "-.--" .. elsif strWord (i) = "Z" then put "--.." .. elsif strWord (i) = " " then put "|" .. elsif strWord (i) = "0" then put "-----" elsif strWord (i) = "1" then put ".----" elsif strWord (i) = "2" then put "..---" elsif strWord (i) = "3" then put "...--" elsif strWord (i) = "4" then put "....-" elsif strWord (i) = "5" then put "....." elsif strWord (i) = "6" then put "-...." elsif strWord (i) = "7" then put "--..." elsif strWord (i) = "8" then put "---..." elsif strWord (i) = "9" then put "---- ." elsif strWord (i) = "." then put ".-.-.-" elsif strWord (i) = "," then put "--..--" elsif strWord (i) = "?" then put "..--.." elsif strWord (i) = "'" then put ".----." elsif strWord (i) = "!" then put "-.-.--" elsif strWord (i) = "/" then put "-..-." end if put " " .. end for |
Author: | md [ Thu Nov 29, 2007 5:31 pm ] |
Post subject: | RE:Morse Code Translator |
That would be much cooler if you used code tags, and arrays. |
Author: | Sean [ Fri Nov 30, 2007 12:50 pm ] | ||
Post subject: | Re: Morse Code Translator | ||
There it is redone in less lines. |
Author: | Dan [ Fri Nov 30, 2007 12:52 pm ] |
Post subject: | RE:Morse Code Translator |
It can still be done in alot less lines if you use arrays or other methods. |
Author: | Sean [ Fri Nov 30, 2007 6:25 pm ] |
Post subject: | Re: Morse Code Translator |
Yes, but that still shortened it.. Was in middle of class doing. |
Author: | WD_40 [ Thu Dec 06, 2007 1:39 pm ] |
Post subject: | RE:Morse Code Translator |
%Bill Daniels %November 29, 2007 %Morse Code %Translates Entered Word Or Phrase Into Morse Code var strWord : string put "Enter a word or phrase" get strWord : * delay (1500) cls for i : 1 .. length (strWord) if strWord (i) = "a" then put ".-" .. elsif strWord (i) = "b" then put "-..." .. elsif strWord (i) = "c" then put "-.-." .. elsif strWord (i) = "d" then put "-.." .. elsif strWord (i) = "e" then put "." .. elsif strWord (i) = "f" then put "..-." .. elsif strWord (i) = "g" then put "--." .. elsif strWord (i) = "h" then put "...." .. elsif strWord (i) = "i" then put ".." .. elsif strWord (i) = "j" then put ".---" .. elsif strWord (i) = "k" then put "-.-" .. elsif strWord (i) = "l" then put ".-.." .. elsif strWord (i) = "m" then put "--" .. elsif strWord (i) = "n" then put "-." .. elsif strWord (i) = "o" then put "---" .. elsif strWord (i) = "p" then put ".- -." .. elsif strWord (i) = "q" then put "--.-" .. elsif strWord (i) = "r" then put ".-." .. elsif strWord (i) = "s" then put "..." .. elsif strWord (i) = "t" then put "-" .. elsif strWord (i) = "u" then put "..-" .. elsif strWord (i) = "v" then put "...-" .. elsif strWord (i) = "w" then put ".--" .. elsif strWord (i) = "x" then put "-..-" .. elsif strWord (i) = "y" then put "-.--" .. elsif strWord (i) = "z" then put "--.." .. elsif strWord (i) = "A" then put ".-" .. elsif strWord (i) = "B" then put "-..." .. elsif strWord (i) = "C" then put "-.-." .. elsif strWord (i) = "D" then put "-.." .. elsif strWord (i) = "E" then put "." .. elsif strWord (i) = "F" then put "..-." .. elsif strWord (i) = "G" then put "--." .. elsif strWord (i) = "H" then put "...." .. elsif strWord (i) = "I" then put ".." .. elsif strWord (i) = "J" then put ".---" .. elsif strWord (i) = "K" then put "-.-" .. elsif strWord (i) = "L" then put ".-.." .. elsif strWord (i) = "M" then put "--" .. elsif strWord (i) = "N" then put "-." .. elsif strWord (i) = "O" then put "---" .. elsif strWord (i) = "P" then put ".--." .. elsif strWord (i) = "Q" then put "--.-" .. elsif strWord (i) = "R" then put ".-." .. elsif strWord (i) = "S" then put "..." .. elsif strWord (i) = "T" then put "-" .. elsif strWord (i) = "U" then put "..-" .. elsif strWord (i) = "V" then put "...-" .. elsif strWord (i) = "W" then put ".--" .. elsif strWord (i) = "X" then put "-..-" .. elsif strWord (i) = "Y" then put "-.--" .. elsif strWord (i) = "Z" then put "--.." .. elsif strWord (i) = " " then put "|" .. elsif strWord (i) = "0" then put "-----" .. elsif strWord (i) = "1" then put ".----" .. elsif strWord (i) = "2" then put "..---" .. elsif strWord (i) = "3" then put "...--" .. elsif strWord (i) = "4" then put "....-" .. elsif strWord (i) = "5" then put "....." .. elsif strWord (i) = "6" then put "-...." .. elsif strWord (i) = "7" then put "--..." .. elsif strWord (i) = "8" then put "---..." .. elsif strWord (i) = "9" then put "---- ." .. elsif strWord (i) = "." then put ".-.-.-" .. elsif strWord (i) = "," then put "--..--" .. elsif strWord (i) = "?" then put "..--.." .. elsif strWord (i) = "'" then put ".----." .. elsif strWord (i) = "!" then put "-.-.--" .. elsif strWord (i) = "/" then put "-..-." .. elsif strWord (i) = "(" then put "-.--." .. elsif strWord (i) = ")" then put "-.--." .. end if put " " .. end for Ok, I've add a few more things and fixed a problem. |
Author: | Dan [ Fri Dec 07, 2007 1:20 pm ] | ||
Post subject: | Re: Morse Code Translator | ||
You should use code or syntax tags when posting code, you can find them by clicking "more tags" when posting. It makes your code alot easyer to read and peoleop more likey to reply. Any how as mentioned above a few times, almost all thos ifs are unnessary. What you can do is make an array of all the dot and dash combinations and have the right combination at the right index so the ascii value of the char it repsents is the index of that dot and dash combnation in the array. Somthing Like
This method sacrifies some memory for efshecey and nicer loking code. This whould be more effshent if turing had a good way to set all the values in the array to "" or a way to tell if an array element was null. P.S. Needless delays are an anti patern: http://compsci.ca/blog/now-loading-loading-bar-anti-pattern/ |
Author: | WD_40 [ Wed Jan 09, 2008 12:07 pm ] |
Post subject: | RE:Morse Code Translator |
I was thinking about making arrays but your spelling is making me change my mind |
Author: | HeavenAgain [ Wed Jan 09, 2008 12:38 pm ] |
Post subject: | RE:Morse Code Translator |
i was thinking about helping you, perhaps writting the whole code for you, but your last post is making me change my mind |
Author: | Dan [ Wed Jan 09, 2008 1:00 pm ] |
Post subject: | Re: RE:Morse Code Translator |
WD_40 @ 9th January 2008, 12:07 pm wrote: I was thinking about making arrays but your spelling is making me change my mind
And you attitude is making me lock this post and remove the solution that was just posted. Your accounting is also getting a warning, we do not tolerate insulating people who are trying to help you and doing it to an mod/admin of the site is even a worse idea. P.S. To users that where posting a solution for him, it is best to give helpful hints and advice then to do code for them (esptaly when they are being rude about it.) |