Morse code is a sequence of dashes and dots that can be used to represent a mess
ID: 3802308 • Letter: M
Question
Morse code is a sequence of dashes and dots that can be used to represent a message in English.
Each letter in a particular alphabet is represented by a unique pattern of dashes and dots in
Morse code. You can find more details about the Morse code on Wikipedia.
In this project, your job is to create a code that can convert an English string into Morse code.
Then you can either beep the message or flash it (using any graphics library).
Your code should also be able to convert Morse code into English text. (You may not be able
to do it directly. Look up Quinary Form of Morse Code.)
A few things to keep in mind are:
1. Graphics (nothing fancy) can be added to flash the Morse code.
2. File handling (i.e. saving the Morse code in a text file)
NOTE: The code should be in " C Language/ C+"
Explanation / Answer
function [output] = english2morse(text)
definitions = {' .-' ' -...' ' -.-.' ' -..' ' .' ' ..-.' ' --.' ' ....' ' ..' ' .---' ' -.-' ' .-..' ' --' ' -.' ' ---' ' .--.' ' --.-' ' .-.' ' ...' ' -' ' ..-' ' ..-' ' .--' ' -..-' ' -.--' ' --..' ' ' '-----' '.----' '..---' '...--' '....-' '.....' '-....' '--...' '---..' '----.' '.-.-.-' '--..--' '..--..' '..--.' '---...' '.-..-.' '.----.' '-...-'};
output = definitions(text);
end
//2nd file (morse2english)
clc
clear
i = 1;
/* Asks user for txt, and checks to see if the input is valid, ifnot, get
new user input, else break while loop and continue program exectution*/
while i == 1
disp('Program converts strings to morce code. ONLY ACCEPTS: A-Z a-z 0-9 , . , ? ! : " `')
pause(1)
text = input('Enter a string: ', 's');
text = lower(text)
disp('Checking to see if correct values entered.')
converted = zeros(1, length(text))
for x = 1:length(text)
// for lowercase letters
if text(x) >= 97 && text(x) <= 122
//for numberals 0-9
converted(x) = double(text(x) - 96);
i = 0;
elseif text(x) >= 48 && text(x) <= 57
converted(x) = text(x) - 20
i = 0;
//for special characters, listed above
elseif text(x) == 46 || text(x) == 44 || text(x) == 63 || text(x) == 33 || text(x) == 58 || text(x) == 34 || text(x) == 39 || text(x) == 61
switch text(x) == 46 || text(x) == 44 || text(x) == 63 || text(x) == 33 || text(x) == 58 || text(x) == 34 || text(x) == 39 || text(x) == 61
case text(x) == 46
converted(x) = text(x) - 8
case text(x) == 44
converted(x) = text(x) - 5
case text(x) == 63
converted(x) = text(x) - 23
case text(x) == 33
converted(x) = text(x) + 8
case text(x) == 58
converted(x) = text(x) - 16
case text(x) == 34
converted(x) = text(x) + 9
case text(x) == 39
converted(x) = text(x) +5
case text(x) == 61
converted(x) = text(x) - 16
end
i = 0;
else
i = 1;
end
end
end
disp(converted)
disp(english2morse(converted))
/*if u want to debugg then the process will be like
Values passed to english2morse() function
1 - 26 = a - z
27 = white space
28 - 37 = 0 - 9
38 -45 = special characters.
SPECIAL CHARACTERS will be enclosed in: 1 [ ], 2 morse equivalent given,
and 3 ascii value given
[ . ] .-.-.- 46
[ , ] --..-- 44
[ ? ] ..--.. 63
[ ! ] ..--. 33
[ : ] ---... 58
[ " ] .-..-. 34
[ ' ] .----. 39
[ = ] -...- 61
send to english to morse code converting function
all_tog = english2morse(converted);
Create new string, 1 row, and all the collumns of all_tog, tthe morse codestring*/
disp('Your string in morse code:')
pause(1)
new = sprintf('%s', all_tog{1,:});
disp(text)
disp(new)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.