Westonci.ca offers quick and accurate answers to your questions. Join our community and get the insights you need today. Our platform provides a seamless experience for finding reliable answers from a knowledgeable network of professionals. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.
Sagot :
The C++ program that shows how to demonstrate Morse code is given below:
C++ Code
// CPP program to demonstrate Morse code
#include <iostream>
using namespace std;
// function to encode a alphabet as
// Morse code
string morseEncode(char x)
{
// refer to the Morse table
// image attached in the article
switch (x) {
case 'a':
return ".-";
case 'b':
return "-...";
case 'c':
return "-.-.";
case 'd':
return "-..";
case 'e':
return ".";
case 'f':
return "..-.";
case 'g':
return "--.";
case 'h':
return "....";
case 'i':
return "..";
case 'j':
return ".---";
case 'k':
return "-.-";
case 'l':
return ".-..";
case 'm':
return "--";
case 'n':
return "-.";
case 'o':
return "---";
case 'p':
return ".--.";
case 'q':
return "--.-";
case 'r':
return ".-.";
case 's':
return "...";
case 't':
return "-";
case 'u':
return "..-";
case 'v':
return "...-";
case 'w':
return ".--";
case 'x':
return "-..-";
case 'y':
return "-.--";
case 'z':
return "--..";
case '1':
return ".----";
case '2':
return "..---";
case '3':
return "...--";
case '4':
return "....-";
case '5':
return ".....";
case '6':
return "-....";
case '7':
return "--...";
case '8':
return "---..";
case '9':
return "----.";
case '0':
return "-----";
default:
cerr << "Found invalid character: " << x << ' '
<< std::endl;
exit(0);
}
}
void morseCode(string s)
{
// character by character print
// Morse code
for (int i = 0; s[i]; i++)
cout << morseEncode(s[i]);
cout << endl;
}
// Driver's code
int main()
{
string s = "geeksforgeeks";
morseCode(s);
return 0;
}
Read more about C++ programming here:
https://brainly.com/question/20339175
#SPJ1
Visit us again for up-to-date and reliable answers. We're always ready to assist you with your informational needs. We hope you found this helpful. Feel free to come back anytime for more accurate answers and updated information. We're glad you chose Westonci.ca. Revisit us for updated answers from our knowledgeable team.