PLEASE EDIT MY CODE: 10.17: Morse Code Converter Morse code is a code where each
ID: 3936853 • Letter: P
Question
PLEASE EDIT MY CODE: 10.17: Morse Code Converter
Morse code is a code where each letter of the English alphabet, each digit, and various punctuation characters are represented by a series of dots and dashes. Table 10-8 from the textbook shows part of the code.
Write a program that asks the user to enter a string , and then converts that string to Morse code. Note that Morse code represents both upper and lower case letters so that both 'A' and 'a' will be converted to ".-".
Input Validation.
None.
#include <iostream>
using namespace std;
int main()
{char morse[37][6]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
"-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-",
"..-","...-",".--","-..-","-.--","--..",".----","..---","...--",
"....-",".....","-....","--...","---..","----.","-----"," "};
char input[50];
char letnum[37]={'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','6',
'7','8','9','0',' '};
int i=0,j,k;
cout<<"input a string: ";
cin.getline(input,37);
while(input[i]!='')
{for(j=0;j<37;j++)
{if(toupper(input[i])==letnum[j])
{for(k=0;k<strlen(morse[j]);k++)
cout<<morse[j][k];
cout<<" " ;
}
}
i++;
}
cout<<endl;
system("pause");
return 0;
}
Algorithm Step1: Prompt the user input any string to convert into marse code Step2: Get the characters from the first to last position of the given string Step3: Convert the character to uppercase Step4: Call the getCode function to get the marse code of the character Step5: Append the marse code of the character Step6: Display the marse code of the given stringExplanation / Answer
#include <iostream>
#include <string.h>
using namespace std;
int main()
{char morse[37][6]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
"-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-",
"..-","...-",".--","-..-","-.--","--..",".----","..---","...--",
"....-",".....","-....","--...","---..","----.","-----"," "};
char input[50];
char letnum[37]={'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','6',
'7','8','9','0',' '};
int i=0,j,k;
cout<<"input a string: ";
cin.getline(input,37);
while(input[i]!='')
{for(j=0;j<37;j++)
{if(toupper(input[i])==letnum[j])
{for(k=0;k<strlen(morse[j]);k++)
cout<<morse[j][k];
cout<<" " ;
}
}
i++;
}
cout<<endl;
system("pause");
return 0;
}
------------------------------output----------------------------------------
input a string: jay007
.--- .- -.-- ----- ----- --...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.