Páginas

NIMADRES

Convertir a Codigo Morse en C++

#include <iostream>
#include <windows.h>

void Insertar(char[]);
void Morse(char[]);

void Menu()
{
   std::cout<<"\t============ CODIGO MORSE =============\n\n";
   std::cout<<"\t________________________________________\n";
   std::cout<<"\t|A .-    |  B -... |  C -.-. |  D -..  |\n";
   std::cout<<"\t|E .     |  F ..-. |  G --.  |  H .... |\n";                   
   std::cout<<"\t|I ..    |  J .--- |  K -.-  |  L .-.. |\n";
   std::cout<<"\t|M --    |  N -.   |  O ---  |  P .--. |\n";
   std::cout<<"\t|Q --.-  |  R .-.  |  S ...  |  T -    |\n";
   std::cout<<"\t|U .-.   |  V ...- |  W .--  |  X -..- |\n";
   std::cout<<"\t|Y -.--  |  Z --.. |         |         |\n";
   std::cout<<"\t________________________________________\n";
}
 
int main()
{
   char String[50];
   
   Menu();
   Insertar(String);
   Morse(String);
  
  
  
   std::cin.get();
   return 0;
}

void Insertar(char String[])
{
std::cout<<"Ingresa una Frase: ";
std::cin.getline(String,50);
//std::cin.getline(String,50);
} 

void Morse(char String[])
{
   std::cout<<"La frase escrita en codigo morse es: ";
  
   for(int i = 0; String[i] != 0;++i)
   {
       std::cout<<"  ";
       switch (String[i])
       {
           case 65: case 97:
               
               std::cout<< ".-";//A
               system("color 0a");
               break;
                   break;
                  
           case 66: case 98:
               
               std::cout<< "-...";//B
               system("color 0b");
               break;
          
           case 67: case 99:
               
               std::cout<< "-.-.";//C
               system("color 0c");
               break;
          
           case 68: case 100:
          
               std::cout<< "-..";//D
               system("color 0e");
               break;
          
           case 69: case 101:
          
               std::cout<< ".";//E
               system("color 0f");
               break;
          
           case 70: case 102:
          
               std::cout<< "..-.";//F
               system("color 1a");
               break;
          
           case 71: case 103:
          
               std::cout<< "--.";//G
               system("color 1b");
               break;
          
           case 72: case 104:
          
               std::cout<< "....";//H
               system("color 1c");
               break;
          
           case 73: case 105:
          
               std::cout<< "..";//I
               system("color 1d");
               break;
          
           case 74: case 106:
          
               std::cout<< ".---";//J
               system("color 1e");
               break;
          
           case 75: case 107:
          
               std::cout<< "-.-";//K
               system("color 0a");
               break;
          
           case 76: case 108:
          
               std::cout<< ".-..";//L
               system("color 0a");
               break;
          
           case 77: case 109:
          
               std::cout<< "--";//M
               system("color 0a");
               break;
          
           case 78: case 110:
          
               std::cout<< "-.";//N
               system("color 2e");
               break;
          
           case 79: case 111:
          
               std::cout<< "---";//O
               system("color 1d");
               break;
          
           case 80: case 112:
          
               std::cout<< ".--.";//P 
               system("color d1");
               break;
          
           case 81: case 113:
          
               std::cout<< "--.-";//Q
               system("color d4");
               break;
          
           case 82: case 114:
          
               std::cout<< ".-.";//R
               system("color 4d");
               break;
          
           case 83: case 115:
          
               std::cout<< "...";//S
               system("color 3c");
               break;
          
           case 84: case 116:
          
               std::cout<< "-";//T
               system("color ac");
               break;
          
           case 85: case 117:
          
               std::cout<< ".-.";//U
               system("color 3a");
               break;
          
           case 86: case 118:
          
               std::cout<< "...-";//V
               system("color e3");
               break;
          
           case 87: case 119:
          
               std::cout<< ".--";//W
               system("color c0");
               break;
          
           case 88: case 120:
          
               std::cout<< "-..-";//X
               system("color fc");
               break;
          
           case 89: case 121:
          
               std::cout<< "-.--";//Y
               system("color e1");
               break;
                           
           case 90: case 122:
          
               std::cout<< "--..";//Z
               system("color 2e");
               break;
            default:
               std::cout<<" ";
               system("color 0c");
               break;
          
       }
       Sleep(100);
   }
   system("color 0e");
}


2 comentarios: