Respuesta :
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