Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Morse code decoder(translate morse code in to English)
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rangers53




PostPosted: Sun Dec 08, 2013 11:40 pm   Post subject: Morse code decoder(translate morse code in to English)

import GUI
var English : array 1 .. 44 of char := init ("A", "B", "C", "D", "E", "F",
"G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
"V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "7", "8", "9", "0", ",",
".", "!", "?", ":", "/", "(", chr (34), ")")


var morse : array 1 .. 44 of string := init (".-", "-...", "-.-.", "-..", ".",
"..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.",
"--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".----", "..---",
"....-", ".....", "-....", "--...", "---..", "----.", "-----", ".-.-.-", "--..--",
"-.-.--", "..--..", "---...", "-..-.", "-.--.", ".-..-.", "-.--.-")



var input : string
var word : string := ""
var answer : string
var space : boolean := false
var filea, fileb : int
var key : string (1)
var renew : boolean := false


proc screentofileb
open : fileb,"", put
word := ""
for k : 1 .. length (input)
if input (k) not= " " and k not= length (input) then
word := word + input (k)
end if
if input (k) = " " then
for l : 1 .. 44
if word = morse (l) then
put English (l) ..
delay (50)
end if
end for
end if
if k <= length (input) then
word := word + input (k)
for l : 1 .. 44
if word = morse (l) then
put : fileb, English (l)..
end if
end for
end if
if k <= length (input)-2 and
input (k) + input (k + 1) + input (k + 2) = " " then
put : fileb, " "..
end if
end for
close : fileb
end screentofileb
proc decode
cls
put "Enter the morse code"
word := ""
get input : *
for k : 1 .. length (input)
if input (k) not= " " and k not= length (input) then
word := word + input (k)
end if
if input (k) = " "then
for l : 1 .. 44
if word = morse(l)then
put English(l)..
delay (40)
end if
end for
word :=""
end if
if k = length (input) then
word := word + input(k)
for l : 1..44
if word = morse(l)then
put English(l)..
delay (40)
end if
end for
end if
if k <= length (input)-2 and
input (k) + input (k + 1) + input (k + 2) = " "then
put " " ..
end if
end for
put ""
put ""

loop
get answer
if answer = "Y" then
screentofileb
end if
if answer not= "Y" and answer not= "N" then
put "Enter again"
end if
exit when answer = "Y" or answer = "N"
end loop
put " press and key to back to menu"
renew := true
setscreen ("nocursor")
getch (key)
GUI.Quit
end decode
proc fileatofileb
word := ""
open : filea, "Morse.txt", get
open : fileb, "English.txt", put
loop
exit when eof (filea)
get : filea, input : 1
if input = " " and space then
put : fileb, " " ..
space := false
end if
if input not=""then
space :=false
word := word + input
end if
if input = " " and word not= " "then
for l : 1 .. 44
if word = morse (l) then
put : fileb, English (l)..
end if
end for

end if
end loop
for l : 1 .. 44
if word = morse (l)then

put : fileb, English (l) ..
delay (20)
end if
end for
close : filea
close : fileb
end fileatofileb
proc fileatonscreen
cls
word :=""
open : filea, "Morse.txt", get
loop
exit when eof (filea)
get : filea, input : 1
if input = " " and space then
put "" ..
space := false
end if
if input not= "" then
space := false
word := word + input
end if
if input = " " and word not= ""then
for l : 1 .. 44
if word = morse (l)then
put English (l)..
delay (20)
end if
end for
word :=""
space := true
end if
end loop
for l : 1 .. 44
if word = morse (l)then
put English (l)..
delay (20)
end if
end for
close : filea
put ""
put ""

loop
get answer
if answer = "Y" then
fileatofileb
end if
if answer not= "Y" then
put "Enter again"
end if
exit when answer = "Y" or answer = "N"
end loop
put "Press any key to lack to menu"
setscreen ("nocursor")
getch (key)
renew := true
GUI.Quit
end fileatonscreen
proc menu
setscreen ("cursor")
renew := false
var font : int
var pic : int
pic := Pic.FileNew ("C:/Turing work/imgres.jpg")
Pic.Draw (pic, 180, 130, picMerge)
font := Font.New ("Arial :30:bold")
Font.Draw ("Morse Code Decoder", 140, 340, font, red)
Font.Draw ("", 330, 340, font, green)
var button1 : int := GUI.CreateButton
(10, 230, 100, "Translate morse code", decode)
var button2 : int := GUI.CreateButton
(10, 180, 100, "Enter for a file", fileatonscreen)
loop
exit when GUI.ProcessEvent and renew
end loop
end menu
loop
cls
menu
end loop
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: