#include <iostream>
#include <vector>
#include <stdio.h>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;
int main ()
{
char morse[29] [7]={".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.","--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".--.-" , ".-.-", "---."};
char text [29] [3]={ "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", "\x86", "\x84", "\x94"};
int j, k;
int borja=0, sok, count=0;
unsigned int i;
while (1)
{
int find_string = 0;
int stop_string = 29;
cout << "What do you want to do?"<<endl
<< "(3) Translate to morse code"<<endl
<< "(2) Translate from morse"<<endl
<< "(1) Exit"<<endl;
cin >> borja;
if (borja==3)
{
string skrift;
cout << "--------------------------" <<endl
<< "You have chosen to convert" << endl
<< "From text to morse code," <<endl
<< "What should i translate? : "<<endl;
cin >> skrift;
cout << endl << endl << skrift << " is in morse code : ";
unsigned int str_lenght;
str_lenght=skrift.size();
cout << endl;
for (i=0;i<str_lenght;i++)
{
find_string=0;
while (find_string < stop_string)
{
if (skrift[i]==text[find_string][0])
{
cout << morse[find_string] << " ";
break;
}
else
find_string = find_string+1;
}
}
}
else if (borja==2)
{
char skrift[50];
cout << "--------------------------" <<endl
<< "You have chosen to convert" << endl
<< "from morse code to text," <<endl
<< "What should i translate? : "<<endl;
skrift.getline(skrift, 50, endl) >> skrift;
cout << endl << endl << skrift << "is in text : ";
unsigned int str_lenght;
str_lenght=50;
cout << endl;
for (i=0;i<str_lenght;i++)
{
find_string=0;
while (find_string < stop_string)
{
if (skrift[i]==morse[find_string][0])
{
cout << text[find_string];
break;
}
else
{
find_string = find_string+1;
}
}
}
}
else
break;
cout << endl << endl << endl << endl;
}
cin.get();
return 0;
}
|