Morse Code Translator
Author |
Message |
WD_40
|
Posted: 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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
md
|
Posted: 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. |
|
|
|
|
|
Sean
|
Posted: Fri Nov 30, 2007 12:50 pm Post subject: Re: Morse Code Translator |
|
|
code: | %Bill Daniels
%November 29, 2007
%Morse Code
%Translates Entered Word Or Phrase Into Morse Code
%Revised By Sean
var strWord : string
put "Enter a word or phrase: "..
get strWord : *
for i : 1 .. length (strWord)
if strWord (i) = "a" or strWord (i) = "A" then
put ".-" ..
elsif strWord (i) = "b" or strWord (i) = "B" then
put "-..." ..
elsif strWord (i) = "c" or strWord (i) = "C" then
put "-.-." ..
elsif strWord (i) = "d" or strWord (i) = "D" then
put "-.." ..
elsif strWord (i) = "e" or strWord (i) = "E" then
put "." ..
elsif strWord (i) = "f" or strWord (i) = "F" then
put "..-." ..
elsif strWord (i) = "g" or strWord (i) = "G" then
put "--." ..
elsif strWord (i) = "h" or strWord (i) = "H" then
put "...." ..
elsif strWord (i) = "i" or strWord (i) = "I" then
put ".." ..
elsif strWord (i) = "j" or strWord (i) = "J" then
put ".---" ..
elsif strWord (i) = "k" or strWord (i) = "K" then
put "-.-" ..
elsif strWord (i) = "l" or strWord (i) = "L" then
put ".-.." ..
elsif strWord (i) = "m" or strWord (i) = "M" then
put "--" ..
elsif strWord (i) = "n" or strWord (i) = "N" then
put "-." ..
elsif strWord (i) = "o" or strWord (i) = "O" then
put "---" ..
elsif strWord (i) = "p" or strWord (i) = "P" then
put ".- -." ..
elsif strWord (i) = "q" or strWord (i) = "Q" then
put "--.-" ..
elsif strWord (i) = "r" or strWord (i) = "R" then
put ".-." ..
elsif strWord (i) = "s" or strWord (i) = "S" then
put "..." ..
elsif strWord (i) = "t" or strWord (i) = "T" then
put "-" ..
elsif strWord (i) = "u" or strWord (i) = "U" then
put "..-" ..
elsif strWord (i) = "v" or strWord (i) = "V" then
put "...-" ..
elsif strWord (i) = "w" or strWord (i) = "W" then
put ".--" ..
elsif strWord (i) = "x" or strWord (i) = "X" then
put "-..-" ..
elsif strWord (i) = "y" or strWord (i) = "Y" then
put "-.--" ..
elsif strWord (i) = "z" or 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
|
There it is redone in less lines. |
|
|
|
|
|
Dan
|
Posted: 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. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
Sean
|
Posted: 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. |
|
|
|
|
|
WD_40
|
Posted: 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. |
|
|
|
|
|
Dan
|
Posted: 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
Turing: |
var strWord : string
put "Enter a word or phrase"
get strWord : *
var code : array 1 .. 255 of string
%start all elements off as an emetpy string
for i : 1 .. 255
code (i ) := ""
end for
%define all of the transaltions btween ascii and morses code
code (ord ('a')) := ".-"
code (ord ('b')) := "-..."
code (ord ('c')) := "-.-."
code (ord ('d')) := "-.."
%..........
%define all dot and dash combnations
%.........
for i : 1 .. length (strWord )
put code (ord (strWord (i ))) ..
end for
|
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/ |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
WD_40
|
Posted: 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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
HeavenAgain
|
Posted: 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 |
|
|
|
|
|
Dan
|
Posted: 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.) |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
|
|