Get the answers you need at Westonci.ca, where our expert community is dedicated to providing you with accurate information. Get quick and reliable solutions to your questions from knowledgeable professionals on our comprehensive Q&A platform. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently.
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
Thanks for using our service. We aim to provide the most accurate answers for all your queries. Visit us again for more insights. We appreciate your time. Please revisit us for more reliable answers to any questions you may have. Get the answers you need at Westonci.ca. Stay informed by returning for our latest expert advice.