1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
string 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="--.. ",one=".----",two="..---",three="...--",four="....-",five=".....",six="-....",seven="--...",eight="---..",nine="----.",zero="-----";
void morseCode(string text, int n);
void toUpper(string &text);
void check(string word, int n);
int main()
{
string text;
getline(cin, text);
toUpper(text);
morseCode(text, 5);
return 0;
}
void toUpper(string &text){
for(int i=0;i<text.length();i++){
text[i] = toupper(text[i]);
}
}
void morseCode(string text, int n){
char help;
string helpText = text;
cout << "|";
for(int i=0;i<helpText.length();i++){
help = text.at(0);
switch(help){
case 'A':check(A,n);break;
case 'B':check(B,n);break;
case 'C':check(C,n);break;
case 'D':check(D,n);break;
case 'E':check(E,n);break;
case 'F':check(F,n);break;
case 'G':check(G,n);break;
case 'H':check(H,n);break;
case 'I':check(I,n);break;
case 'J':check(J,n);break;
case 'K':check(K,n);break;
case 'L':check(L,n);break;
case 'M':check(M,n);break;
case 'N':check(N,n);break;
case 'O':check(O,n);break;
case 'P':check(P,n);break;
case 'Q':check(Q,n);break;
case 'R':check(R,n);break;
case 'S':check(S,n);break;
case 'T':check(T,n);break;
case 'U':check(U,n);break;
case 'V':check(V,n);break;
case 'W':check(W,n);break;
case 'Y':check(Y,n);break;
case 'X':check(X,n);break;
case 'Z':check(Z,n);break;
case '1':check(one,n);break;
case '2':check(two,n);break;
case '3':check(three,n);break;
case '4':check(four,n);break;
case '5':check(five,n);break;
case '6':check(six,n);break;
case '7':check(seven,n);break;
case '8':check(eight,n);break;
case '9':check(nine,n);break;
case '0':check(zero,n);break;
default : cout << "\t\t|";
}
text.erase(0,1);
}
}
void check(string word, int n){
for(int i=0;i<n;i++){
if(word.at(i)=='.'){
cout << ".";
Sleep(0);
}else if(word.at(i)=='-'){
cout << "-";
Sleep(0);
}else{
break;
}
}
cout << "|";
}
|