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
|
#include <iostream>
#include <map>
#include <string>
void display_menu();
int main()
{
char aKey[] =
{
'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', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
};
std::string mKey[] =
{
".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
"-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-",
"..-","...-",".--","-..-","-.--","--..","-----",".----",
"..---","...--","....-",".....","-....","--...","---..","----."
};
int key_sizeA = sizeof(aKey)/sizeof(char);
std::map<char, std::string> alpha_to_morse;
std::map<char, std::string>::iterator it_a_m;
char alpha_input;
std::map< std::string, char> morse_to_alpha;
std::map< std::string, char>::iterator it_m_a;
std::string morse_input;
display_menu();
char option = 'x';
for(int i = 0; i < key_sizeA; i++)
{
alpha_to_morse.insert(std::pair<char, std::string>(aKey[i],mKey[i]) );
morse_to_alpha.insert(std::pair<std::string,char>(mKey[i],aKey[i]) );
}
while ( std::cin >> option && tolower(option) != 'q')
{
switch(option)
{
case '1':
std::cout << "Please enter alpha characters, / to end:\n";
while( std::cin.get(alpha_input) && alpha_input != '/' )
{
if(alpha_input == ' ')
std::cout << '|'; // vertical bar to separate words
it_a_m = alpha_to_morse.find(alpha_input);
std::cout << it_a_m -> second << ' ';
}
break;
case '2':
std::cout << "Please enter morse string:\n";
while( std::cin >> morse_input && morse_input != "/" )
{
if(morse_input == "|")
std::cout << " ";
else
{
it_m_a = morse_to_alpha.find(morse_input);
std::cout << it_m_a -> second;
}
}
break;
default:
std::cout << "Invalid choice\n";
}
display_menu();
}
return 0;
}
void display_menu()
{
std::cout << "*********************\n";
std::cout << "* 1. alpha -> morse *\n";
std::cout << "* 2. morse -> alpha *\n";
std::cout << "* q Quit program *\n";
std::cout << "*********************\n";
}
| |