Să se scrie un program care să traducă un text
dat în cod Morse. Să se producă și sunetele
specifice.
(in c++)
Răspunsuri la întrebare
Răspuns:
#include <iostream>
#include <cstdio>
#include <stdlib.h>
using namespace std;
char text[10000];
int i,k;
int main()
{
for (i = 0; i < 4; i++)
{
cin >> text[i];
k++;
if (text[i] == '\n')
break;
}
for (i = 0; i <= k; i++)
switch (text[i])
{
case 'a': cout<<"._"<<" "; break;
case 'b': cout<<"_..." << " "; break;
case 'c': cout<<"_._." << " "; break;
case 'd': cout<<"_.." << " "; break;
case 'e': cout<<"." << " "; break;
case 'f': cout<<".._." << " "; break;
case 'g': cout<<"__." << " "; break;
case 'h': cout<<"...." << " "; break;
case 'i': cout<<".." << " "; break;
case 'j': cout<<".___" << " "; break;
case 'k': cout<<"_._" << " "; break;
case 'l': cout<<"._.." << " "; break;
case 'm': cout<<"__" << " "; break;
case 'n': cout<<"_." << " "; break;
case 'o': cout<<"___" << " "; break;
case 'p': cout<<".__." << " "; break;
case 'q': cout<<"__._" << " "; break;
case 'r': cout<<"._." << " "; break;
case 's': cout<<"..." << " "; break;
case 't': cout<<"_" << " "; break;
case 'u': cout<<".._" << " "; break;
case 'v': cout<<"..._" << " "; break;
case 'w': cout<<".__" << " "; break;
case 'x': cout<<"_.._" << " "; break;
case 'y': cout<<"_.__" << " "; break;
case 'z': cout<<"__.." << " "; break;
default: cout<<" "; break;
}
}
Explicație:
Codul afiseaza codul, dar nu reproduce sunetele.